Bird
0
0

What is wrong with this Kafka CQRS query handler code snippet?

medium📝 Debug Q7 of 15
Kafka - Event-Driven Architecture
What is wrong with this Kafka CQRS query handler code snippet?
consumer.subscribe(['orders-events'])
for msg in consumer:
    update_read_model(msg.value)
    producer.send('orders-commands', {'orderId': msg.value['orderId'], 'action': 'refresh'})
AQuery handler should not send commands back to commands topic
BConsumer should subscribe to commands topic instead
Cupdate_read_model should not be called inside the loop
DThe topic names are reversed
Step-by-Step Solution
Solution:
  1. Step 1: Understand query handler role

    Query handler reads events and updates read models; it should not send commands.
  2. Step 2: Identify misuse of producer

    Sending commands from query handler breaks CQRS separation and can cause loops.
  3. Final Answer:

    Query handler should not send commands back to commands topic -> Option A
  4. Quick Check:

    Query handler only reads events and updates models [OK]
Quick Trick: Query side never sends commands [OK]
Common Mistakes:
  • Sending commands from query handler
  • Subscribing consumer to wrong topic
  • Misusing update functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes