Microservices Data Management Strategies 2 — Questions and Answers
Question 1: In a microservices architecture, what does the 'Database per Service' pattern primarily ensure?
- Each service owns and encapsulates its own data store (Correct answer)
- All services share a single relational database
- Services bypass APIs to query each other's tables
- Data is never persisted to disk
Correct answer: Each service owns and encapsulates its own data store
Database per Service gives each microservice exclusive ownership of its data, preventing tight coupling at the data layer.
Question 2: Which pattern is commonly used to maintain data consistency across services without distributed transactions?
- Saga pattern (Correct answer)
- Two-phase commit lock
- Global table lock
- Synchronous join query
Correct answer: Saga pattern
The Saga pattern coordinates a sequence of local transactions with compensating actions instead of a distributed transaction.
Question 3: What is a key drawback of sharing a single database across multiple microservices?
- It creates tight coupling and hinders independent deployment (Correct answer)
- It improves service autonomy
- It eliminates the need for APIs entirely
- It guarantees eventual consistency automatically
Correct answer: It creates tight coupling and hinders independent deployment
A shared database couples services through the schema, making independent evolution and deployment difficult.
Question 4: In the Saga pattern, what is a 'compensating transaction'?
- An operation that undoes the effect of a previously completed transaction (Correct answer)
- A transaction that compensates employees
- A backup of the entire database
- A transaction that runs twice for redundancy
Correct answer: An operation that undoes the effect of a previously completed transaction
Compensating transactions reverse prior steps when a later step in the saga fails, restoring consistency.
Question 5: Which approach allows services to maintain a local read-optimized copy of data owned by another service?
- Data replication via event-driven updates (Correct answer)
- Direct synchronous database joins
- Sharing the primary database connection pool
- Disabling all caching
Correct answer: Data replication via event-driven updates
Services can replicate needed data locally and keep it updated through events, avoiding cross-service queries.
Question 6: What does 'eventual consistency' mean in a distributed microservices system?
- Data becomes consistent across services after some delay (Correct answer)
- Data is always immediately consistent everywhere
- Data is never consistent
- Consistency is enforced by a global lock
Correct answer: Data becomes consistent across services after some delay
Eventual consistency means replicas converge to the same state given enough time without immediate synchronization.
Question 7: Which of these is the main reason microservices avoid distributed ACID transactions across services?
- They reduce scalability and increase coupling between services (Correct answer)
- They are faster than local transactions
- They are required by REST APIs
- They guarantee zero latency
Correct answer: They reduce scalability and increase coupling between services
Distributed transactions like 2PC lock resources across services, harming scalability and availability.
In a microservices architecture, what does the 'Database per Service' pattern primarily ensure?