CSI Message Queuing & Event-Driven Architecture 2 — Questions and Answers
Question 1: In RabbitMQ, which exchange type routes messages to queues based on an exact match of the message's routing key?
- Fanout exchange
- Topic exchange
- Direct exchange (Correct answer)
- Headers exchange
Correct answer: Direct exchange
A direct exchange routes messages to queues whose binding key exactly matches the message's routing key, making it suitable for task distribution to specific workers.
Question 2: What is the CQRS pattern and how does it relate to event-driven architectures?
- Command Query Responsibility Segregation — separates read and write models, often using events to sync the write side to read projections (Correct answer)
- Centralized Queue Routing System — a central broker pattern for managing event streams
- Concurrent Query and Response System — a method for parallel event processing
- Cross-Queue Replication Scheme — a redundancy pattern for message queues
Correct answer: Command Query Responsibility Segregation — separates read and write models, often using events to sync the write side to read projections
CQRS separates command (write) and query (read) operations, and pairs naturally with event sourcing: commands emit events that update denormalized read models asynchronously.
Question 3: A system integrator needs to guarantee message ordering within a specific subset of events. Which Kafka feature supports this requirement?
- Consumer group rebalancing
- Topic compaction
- Partition keying by a consistent message attribute (Correct answer)
- Broker replication factor
Correct answer: Partition keying by a consistent message attribute
By assigning a consistent partition key (e.g., customer ID), all messages with the same key are routed to the same partition, preserving order for that key within Kafka's ordered partition log.
Question 4: Which integration pattern uses a persistent store to record outgoing messages before they are sent, ensuring they are eventually delivered even if the broker is temporarily unavailable?
- Circuit breaker pattern
- Transactional outbox pattern (Correct answer)
- Saga orchestration pattern
- Competing consumers pattern
Correct answer: Transactional outbox pattern
The transactional outbox pattern writes the message to a local database table within the same transaction as the business operation, then a relay process publishes it to the broker, preventing message loss.
Question 5: In event-driven microservices, what is a 'saga' pattern used for?
- Compressing event payloads for efficient network transmission
- Managing distributed transactions across multiple services using a sequence of local transactions and compensating events (Correct answer)
- Scheduling periodic batch event generation
- Encrypting event streams between producers and consumers
Correct answer: Managing distributed transactions across multiple services using a sequence of local transactions and compensating events
The saga pattern coordinates multi-step distributed transactions by chaining local transactions and using compensating transactions to roll back completed steps if a later step fails.
Question 6: What does 'consumer group' mean in the context of Apache Kafka?
- A set of producers that share a common schema registry
- A named group of consumers where each partition is consumed by only one member, enabling parallel load-balanced processing (Correct answer)
- A cluster of Kafka brokers that replicate partitions
- A collection of topics grouped by business domain
Correct answer: A named group of consumers where each partition is consumed by only one member, enabling parallel load-balanced processing
A consumer group allows multiple consumer instances to share the work of consuming a topic, with each partition assigned to exactly one consumer in the group at a time for balanced parallel processing.
Question 7: Which of the following is a key characteristic of an idempotent consumer in a message-driven system?
- It acknowledges messages without processing them
- Processing the same message multiple times produces the same outcome as processing it once (Correct answer)
- It only processes messages during off-peak hours
- It transforms messages into a canonical format before storing
Correct answer: Processing the same message multiple times produces the same outcome as processing it once
An idempotent consumer handles at-least-once delivery safely by ensuring that reprocessing a duplicate message does not cause unintended side effects like double charges or duplicate records.
In RabbitMQ, which exchange type routes messages to queues based on an exact match of the message's routing key?