Microservices Data Management Strategies Questions and Answers 1 β Questions and Answers
Question 1: An e-commerce platform uses a choreography-based Saga pattern to process new orders. The 'Order' service emits an 'OrderCreated' event. The 'Inventory' service listens for this event to reserve stock, and the 'Payment' service listens to it to process payment. What is a primary disadvantage of this choreographed approach compared to an orchestrated one?
- It introduces a single point of failure through a central coordinator.
- The overall business transaction flow is not explicitly defined in one place, making it harder to monitor and debug. (Correct answer)
- It leads to tighter coupling between the services because they must directly call each other.
- It cannot support compensating transactions to roll back the process in case of a failure.
Correct answer: The overall business transaction flow is not explicitly defined in one place, making it harder to monitor and debug.
In a choreography-based Saga, each service participates by reacting to events from other services. While this promotes loose coupling, it means the end-to-end business logic is distributed and not centrally defined. This makes it challenging to understand, monitor, and debug the entire workflow, as there is no single orchestrator that explicitly models the process.
Question 2: A financial services application requires that when a user's address is updated, the change is immediately and consistently reflected across the 'Customer Profile', 'Billing', and 'Shipping' services. The business cannot tolerate any temporary inconsistencies. Which data consistency model is most appropriate for this requirement?
- Eventual Consistency
- Causal Consistency
- Strong Consistency (Correct answer)
- Read-Your-Writes Consistency
Correct answer: Strong Consistency
Strong consistency guarantees that all subsequent reads will return the most recent write, ensuring that all services see the same data at the same time. This is critical for financial applications where temporary data divergence is unacceptable. Eventual consistency, while good for availability, allows for temporary inconsistencies which is not suitable for this scenario.
Question 3: A team is building a microservices-based application where different services have vastly different data storage needs. The 'Product Catalog' service deals with semi-structured data and requires flexible schema, while the 'User Authentication' service manages relational data with strict transactional integrity. Which data management strategy allows teams to select the most appropriate database technology for their specific service?
- Database Sharding
- Polyglot Persistence (Correct answer)
- Data Lakehouse
- Centralized Monolithic Database
Correct answer: Polyglot Persistence
Polyglot Persistence is the practice of using different data storage technologies to handle different data storage needs within a single application. This approach aligns perfectly with the microservices principle of using the right tool for the job, allowing each service to use a database that best fits its specific requirements (e.g., a NoSQL database for the catalog and a relational database for user auth).
Question 4: An organization is migrating a legacy monolithic application to microservices. They need a way to synchronize data from the monolith's database to the new microservices' databases in near real-time without modifying the monolith's application code. Which pattern is best suited for this purpose?
- API Composition
- Strangler Fig Pattern
- Change Data Capture (CDC) (Correct answer)
- Transactional Outbox
Correct answer: Change Data Capture (CDC)
Change Data Capture (CDC) is a pattern used to monitor and capture row-level changes (inserts, updates, deletes) in a database's transaction logs and stream these changes as events to other systems. This allows new microservices to stay synchronized with the legacy database without requiring intrusive changes to the original application's code.
Question 5: In a microservices architecture, what is the primary motivation for enforcing the principle of 'Data Ownership', where each service is solely responsible for its own data store?
- To simplify database administration by having a single DBA manage all data.
- To guarantee strong, immediate consistency across the entire system for all transactions.
- To ensure services remain loosely coupled and can be developed, deployed, and scaled independently. (Correct answer)
- To reduce data storage costs by consolidating all data into a single, large database instance.
Correct answer: To ensure services remain loosely coupled and can be developed, deployed, and scaled independently.
The principle of Data Ownership, often implemented as 'Database per Service', is crucial for maintaining the autonomy and loose coupling of microservices. When a service owns its data, its schema can evolve without impacting other services, and it can be scaled independently. This prevents the database from becoming a point of tight coupling that hinders independent development and deployment.
Question 6: A social media application is designed with an eventual consistency model. When a user updates their profile picture, the change might take a few seconds to propagate to all replicas and be visible to their friends. Which of the following is the primary trade-off for accepting this temporary inconsistency?
- Reduced data integrity and higher risk of data corruption.
- Increased query latency and slower read performance.
- Simplified transaction management across distributed services.
- Higher availability and improved performance during network partitions. (Correct answer)
Correct answer: Higher availability and improved performance during network partitions.
According to the CAP theorem, in a distributed system, you can only have two out of three: Consistency, Availability, and Partition Tolerance. Since network partitions are a given in microservices, the trade-off is between strong consistency and high availability. Eventual consistency prioritizes availability, allowing the system to continue accepting reads and writes even if some nodes are temporarily out of sync, thus improving performance and resilience.
An e-commerce platform uses a choreography-based Saga pattern to process new orders.
The 'Order' service emits an 'OrderCreated' event.
The 'Inventory' service listens for this event to reserve stock, and the 'Payment' service listens to it to process payment.
What is a primary disadvantage of this choreographed approach compared to an orchestrated one?