Microservices Data Management Strategies 3 — Questions and Answers
Question 1: What is the primary purpose of the CQRS pattern in microservices?
- Separating read and write models for independent optimization (Correct answer)
- Combining all queries into one giant SQL statement
- Encrypting all command messages
- Eliminating the need for databases
Correct answer: Separating read and write models for independent optimization
CQRS (Command Query Responsibility Segregation) splits read and write models so each can scale and be optimized separately.
Question 2: In Event Sourcing, how is the current state of an entity derived?
- By replaying the sequence of stored events (Correct answer)
- By reading a single mutable row
- By querying a cache only
- By averaging all field values
Correct answer: By replaying the sequence of stored events
Event Sourcing stores state changes as a log of events; current state is reconstructed by replaying them.
Question 3: Which problem does the Transactional Outbox pattern solve?
- Reliably publishing events as part of a local database transaction (Correct answer)
- Encrypting data at rest
- Load balancing HTTP requests
- Generating UUIDs faster
Correct answer: Reliably publishing events as part of a local database transaction
The Outbox pattern writes events to an outbox table in the same transaction as the data change, then publishes them reliably.
Question 4: What is the 'dual-write problem' in microservices data management?
- The risk of inconsistency when writing to a database and a message broker separately (Correct answer)
- Writing the same file twice to disk
- Using two databases for backup
- Writing logs in two formats
Correct answer: The risk of inconsistency when writing to a database and a message broker separately
Dual writes can fail partway, leaving the database and message broker out of sync without an atomic mechanism.
Question 5: Which technique reads a database's transaction log to capture and stream data changes?
- Change Data Capture (CDC) (Correct answer)
- Schema migration
- Connection pooling
- Index rebuilding
Correct answer: Change Data Capture (CDC)
CDC tools like Debezium tail the transaction log to emit change events to other services.
Question 6: A benefit of CQRS combined with separate read databases is:
- Read models can be denormalized and tuned for query performance (Correct answer)
- Writes become impossible
- All consistency issues disappear instantly
- It removes the need for a write database
Correct answer: Read models can be denormalized and tuned for query performance
Separate read stores can be shaped for fast queries independently of the normalized write model.
Question 7: What is a common trade-off when adopting Event Sourcing?
- Increased complexity in querying current state and handling event schema evolution (Correct answer)
- Loss of all audit history
- Inability to scale reads
- No way to store events
Correct answer: Increased complexity in querying current state and handling event schema evolution
Event Sourcing adds complexity around projections, versioning of events, and rebuilding state.
What is the primary purpose of the CQRS pattern in microservices?