Skip to main content
Welcome back. In this lesson we start the warehouse backend UI (the internal web interface) and connect it to the Kafka topic that receives cart/order events. The backend consumes events produced by the front-end and renders them for warehouse packers. Below we walk through the key producer behavior from the frontend, how the warehouse app consumes those events, sample logs, the consumer implementation used by the UI, and how to run and test the dashboard end-to-end.

Producer: front-end order event (context)

When an order is placed in the front-end, the app produces an order event to Kafka. The producer code looks like this:
Producer delivery is asynchronous by default. To ensure delivery before shutdown, either call producer.flush() on shutdown or supply a delivery callback to confirm the message reached the broker.
Example terminal output from the front-end when placing an order:

Configure the backend consumer to connect to your Kafka broker

Open the warehouse UI app (folder: final-projects/warehouse, file: app.py) and locate the Consumer import from confluent_kafka. The consumer configuration needs the broker address in bootstrap.servers. Replace the placeholder with the public IP (and port) of the EC2 instance running Kafka.
The image shows the AWS EC2 dashboard with a running instance named "kafka-server." Details such as the instance ID, state, type, and public IPV4 address are displayed.
Replace bootstrap.servers with the EC2 instance’s public IP and Kafka port (for example 54.234.163.236:9092). This allows the consumer running locally (or from another host) to connect to the Kafka broker.

Consumer configuration notes

Below are the important consumer settings used by the warehouse dashboard and why they matter:
If you generate a new unique group.id on every run and do not commit offsets, the consumer will re-read messages from the earliest offset each time. For normal operation, use a stable group.id and commit offsets to avoid duplicate processing.

Consumer implementation used by the warehouse UI

This implementation polls Kafka for available messages, decodes JSON payloads, skips tombstone messages (value is None), and returns a list of parsed order dictionaries for rendering in the UI.
How the UI uses this function:
  • The dashboard calls get_kafka_messages() when the packer clicks “Refresh Dashboard”.
  • Each returned dict should contain customer_name, delivery_address, products, and total_amount.
  • The frontend renders those fields in an actionable format for packers (items, prices, totals, address).

Running the warehouse UI locally

  1. Open a terminal in the final-projects/warehouse folder.
  2. Start the app:
    • python3 app.py
  3. Open the dashboard in your browser (or use the editor’s “Open in Browser”).

Test the end-to-end flow

  1. Place an order in the shop front-end (e.g., add toy 6, view cart, enter customer name “Rose” and address “Delhi”, then click Place Order). This produces an event to the cartevnt topic.
  2. In the warehouse dashboard, click Refresh Dashboard. The backend consumer will poll Kafka, parse the event, and render it.
The dashboard displays orders in a packer-friendly way (product list, prices, totals, customer, address). You can extend the dashboard to:
  • Auto-refresh on a timer or via WebSocket updates.
  • Group orders into batches for efficient picking.
  • Highlight priority shipments or fragile items.
  • Enrich events with inventory metadata (e.g., rack locations).
The image shows a "Warehouse Packer Dashboard" displaying orders for packing, including products, prices, and total amounts for two customers.
Example extension idea: For each product in the Kafka event, query an inventory service or database to join a rack or location field (e.g., “rack 15”), then include that in the rendered order to speed up picking.

Key takeaway

Kafka serves as the central event bus connecting front-end producers and backend consumers like the warehouse UI. This decouples systems and enables a flexible, event-driven architecture where each service can independently produce or consume events. This completes the end-to-end demo for the warehouse backend UI. See you in the next lesson!

Watch Video

Practice Lab