Skip to content

Instantly share code, notes, and snippets.

@badri
Last active June 9, 2023 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badri/f08ee5ff8896a12dd691295c43fac533 to your computer and use it in GitHub Desktop.
Save badri/f08ee5ff8896a12dd691295c43fac533 to your computer and use it in GitHub Desktop.
Kafka exercise

Create a web service using your preferred programming language and framework (e.g., Python with Flask).

Implement two endpoints:

  1. /orders (POST): Accepts JSON payload representing a product order and publishes it to the Kafka topic "product_orders".
  2. /orders (GET): Retrieves all product orders from the PostgreSQL database and returns them as JSON.

Implement a DB sink connector which reads "product_orders" topic and writes the data to a table called orders in Postgres DB.

Write a Kafka consumer which consumes from "product_orders" and writes to a respective city topic. For ex, in the below order payload:

{
  "order_id": 12345,
  "customer": {
    "name": "John Doe",
    "email": "johndoe@example.com",
    "address": {
      "street": "123 Main St",
      "city": "Chennai",
      "state": "Tamil Nadu",
      "postal_code": "600004"
    }
  },
  "product_name": "Widget",
  "quantity": 2,
  "order_date": "2023-06-09",
  "priority": "medium"
}

will write the message to a topic called Chennai.

Finally, write a consumer which will send an email to customer if the priority field is high. Just implementing a dummy send_email function in consumer is enough.

Considerations

  1. use docker compose for the entire setup. Kubernetes cluster is also OK.
  2. Add a README for this exercise explaining what it does and how to run everything.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment