Skip to content

beakerandjake/kafka-hello-world

Repository files navigation


Logo

kafka-hello-world

Realtime (fake) stock prices with Kafka.

Table of Contents
  1. About
  2. Getting Started
  3. Usage
  4. Architecture Diagram

About

project-screenshot

Created while I was learning Kafka, I needed a stream of realtime data to work with and stock prices came to mind.

The project is composed of different applications which are orchestrated by docker compose.

A single Producer continually publishes price change messages to a topic with multiple Consumers.

  • One Consumer saves each price event to a database.
  • Another Consumer aggregates these rows into time buckets.
  • A final Consumer pushes price events to the frontend via SSE.

(back to top)

Built With

Kafka Postgres Nginx Docker Fastify Vite React Chart.js TailwindCSS

(back to top)

Getting Started

Installation is easy thanks to docker compose, you just need to clone this repository then run the up command.

Prerequisites

Docker Compose must be installed on your machine. It can be installed through docker desktop or docker engine.

Installation

  1. Clone this repo
    git clone https://github.com/beakerandjake/kafka-hello-world
  2. Start the application
    docker compose up -d

To stop the application

docker compose down

(back to top)

Usage

Once the containers are all started navigate to http://localhost:8080 in your browser. You should see prices continually update, if you leave it running you can see the price chart change over time.

To view the price events you can create a console consumer:

docker exec -it kafka kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic stock_price_changes

You can also follow the consumer logs:

docker logs consumer-realtime --follow
docker logs consumer-aggregate --follow

(back to top)

Architecture Diagram

project-architecture

See a specific component's README file for more information.

(back to top)