CMA - Certified Master Architect Architectural Design and Patterns Questions and Answers 1 — Questions and Answers
Question 1: A rapidly growing e-commerce platform is transitioning from a monolithic architecture to microservices. They need to ensure data consistency for transactions that span multiple services, such as processing an order which involves updating inventory, charging the customer, and arranging for shipping. If any of these steps fail, the entire transaction must be rolled back. Which architectural pattern is most suitable for managing this multi-service transaction?
- Circuit Breaker
- Saga Pattern (Correct answer)
- API Gateway
- Strangler Fig Pattern
Correct answer: Saga Pattern
The Saga pattern is designed to manage data consistency across multiple microservices in a distributed transaction. It sequences a series of local transactions and includes compensating transactions to undo changes if a step fails, ensuring the system returns to a consistent state.
Question 2: An enterprise is planning to modernize a large, business-critical legacy monolithic application. A 'big bang' rewrite is considered too risky due to the potential for service disruption. The goal is to incrementally replace parts of the legacy system with new microservices over time, while the entire application remains operational for users. Which design pattern provides a structured approach for this gradual migration?
- Bulkhead Pattern
- Event Sourcing
- Strangler Fig Pattern (Correct answer)
- Command Query Responsibility Segregation (CQRS)
Correct answer: Strangler Fig Pattern
The Strangler Fig pattern is an architectural approach for incrementally migrating a legacy system by gradually replacing specific pieces of functionality with new applications and services. It involves creating a facade that intercepts requests to the old system and routes them to either the legacy code or the new services, allowing the new system to grow over the old one until the legacy system is eventually 'strangled' and decommissioned.
Question 3: A financial services application requires a complete and immutable audit trail of all transactions. For compliance and analytical purposes, the business needs the ability to reconstruct the state of any account at any point in history. Simply storing the current state of the data is insufficient. Which pattern best addresses this requirement?
- Event Sourcing (Correct answer)
- Stateful Service
- Snapshotting
- Transactional Outbox
Correct answer: Event Sourcing
Event Sourcing is a pattern where all changes to an application's state are stored as a sequence of events. This append-only log of events provides a full audit trail and allows for the reconstruction of an entity's state at any point in time by replaying the events. This is ideal for systems requiring strong audit capabilities.
Question 4: A complex system has significantly different requirements for reading and writing data. The read operations are frequent, high-volume, and need to be highly optimized for performance using denormalized data structures. The write operations are less frequent but involve complex business logic and validation on a normalized model. Which pattern would be most effective for architecting this system?
- Microservices Architecture
- Layered Architecture
- Service-Oriented Architecture (SOA)
- Command Query Responsibility Segregation (CQRS) (Correct answer)
Correct answer: Command Query Responsibility Segregation (CQRS)
The Command Query Responsibility Segregation (CQRS) pattern separates the models for reading (Query) and writing (Command) data. This allows for independent optimization and scaling of the read and write workloads, making it ideal for scenarios with asymmetric operational needs.
Question 5: Which of the following is a significant drawback when choosing a microservices architecture over a monolithic architecture for a small, startup team with a tight deadline for their initial product launch?
- Reduced scalability for individual components.
- Increased development velocity for a small team.
- Higher initial operational complexity and overhead. (Correct answer)
- Tighter coupling between application components.
Correct answer: Higher initial operational complexity and overhead.
While microservices offer scalability and flexibility, they introduce significant operational overhead and complexity, especially for a small team. This includes setting up and managing distributed systems, service discovery, inter-service communication, and distributed monitoring, which can slow down initial development compared to a simpler monolithic approach.
Question 6: In a distributed system implementing the Saga pattern for a long-running transaction, one of the local transactions fails. What is the primary mechanism used by the Saga pattern to ensure data consistency across the services?
- The system automatically retries the failed transaction indefinitely.
- A two-phase commit (2PC) protocol is initiated to roll back all transactions.
- A series of compensating transactions are executed to undo the changes made by preceding successful transactions. (Correct answer)
- The entire transaction is aborted, and all participating services are restored from a previous snapshot.
Correct answer: A series of compensating transactions are executed to undo the changes made by preceding successful transactions.
The core principle of the Saga pattern for failure management is the use of compensating transactions. If a local transaction in the sequence fails, the saga executes a series of compensating transactions in reverse order to undo the work completed by the previous successful local transactions, thereby maintaining data consistency.
A rapidly growing e-commerce platform is transitioning from a monolithic architecture to microservices.
They need to ensure data consistency for transactions that span multiple services, such as processing an order which involves updating inventory, charging the customer, and arranging for shipping.
If any of these steps fail, the entire transaction must be rolled back.
Which architectural pattern is most suitable for managing this multi-service transaction?