Microservices Microservices 3 β Questions and Answers
Question 1: The Saga pattern is used primarily to manage:
- Distributed transactions across multiple services without a global lock (Correct answer)
- UI rendering
- Local file storage
- Single-database ACID commits
Correct answer: Distributed transactions across multiple services without a global lock
Sagas coordinate distributed transactions via a sequence of local transactions and compensations.
Question 2: In a choreography-based saga, services coordinate by:
- Publishing and reacting to events without a central orchestrator (Correct answer)
- A single controller commanding each step
- Sharing one database lock
- Calling a monolith
Correct answer: Publishing and reacting to events without a central orchestrator
Choreography relies on services emitting and reacting to events, with no central coordinator.
Question 3: What is a compensating transaction in a saga?
- An action that undoes the effect of a previously completed step on failure (Correct answer)
- A retry of the same step forever
- A database backup
- A new microservice
Correct answer: An action that undoes the effect of a previously completed step on failure
Compensating transactions semantically reverse prior steps when a later step fails.
Question 4: The Strangler Fig pattern is used to:
- Incrementally migrate a monolith to microservices by gradually replacing functionality (Correct answer)
- Delete all code at once
- Merge services into one binary
- Encrypt the monolith
Correct answer: Incrementally migrate a monolith to microservices by gradually replacing functionality
The Strangler Fig pattern gradually routes functionality away from a monolith to new services.
Question 5: What problem does the CQRS pattern address?
- Separating read and write models for scalability and clarity (Correct answer)
- Combining all services into one
- Removing all databases
- Disabling logging
Correct answer: Separating read and write models for scalability and clarity
CQRS separates command (write) and query (read) responsibilities into different models.
Question 6: Event sourcing stores application state as:
- A sequence of immutable events that can be replayed (Correct answer)
- Only the latest snapshot row
- Temporary in-memory values
- Compiled binaries
Correct answer: A sequence of immutable events that can be replayed
Event sourcing persists every state change as an append-only log of events.
Question 7: Which challenge is introduced by eventual consistency in microservices?
- Data may be temporarily out of sync across services until updates propagate (Correct answer)
- All data is always instantly consistent
- Databases stop working
- Services cannot communicate at all
Correct answer: Data may be temporarily out of sync across services until updates propagate
Eventual consistency means replicas converge over time, so brief inconsistencies can occur.
The Saga pattern is used primarily to manage: