CPSA Architectural Patterns and Styles 3 — Questions and Answers
Question 1: Which microservices pattern coordinates a sequence of local transactions across multiple services using events or messages to maintain data consistency?
- Two-Phase Commit (2PC)
- Saga Pattern (Correct answer)
- Outbox Pattern
- Bulkhead Pattern
Correct answer: Saga Pattern
The Saga pattern breaks a distributed transaction into a series of local transactions, each publishing events that trigger the next step, with compensating transactions for rollback.
Question 2: In microservices architecture, an API Gateway primarily serves which function?
- Persisting service configuration in a central database
- Acting as a single entry point that routes, aggregates, and cross-cuts concerns for client requests (Correct answer)
- Replacing the need for service-to-service communication
- Managing database schema migrations across services
Correct answer: Acting as a single entry point that routes, aggregates, and cross-cuts concerns for client requests
An API Gateway consolidates routing, authentication, rate limiting, and response aggregation so clients interact with one endpoint instead of many services.
Question 3: The Circuit Breaker pattern in distributed systems is designed to prevent which specific failure mode?
- Data corruption during network partitions
- Cascading failures caused by repeatedly calling a failing remote service (Correct answer)
- Race conditions in concurrent database writes
- Memory leaks in long-running service instances
Correct answer: Cascading failures caused by repeatedly calling a failing remote service
A Circuit Breaker monitors failure rates and, after a threshold is exceeded, stops forwarding calls to the failing service, giving it time to recover and preventing overload.
Question 4: What is the key characteristic that distinguishes Choreography-based sagas from Orchestration-based sagas?
- Choreography uses a central coordinator that directs each service step by step
- In choreography, each service reacts to events autonomously without a central controller (Correct answer)
- Orchestration requires services to publish events; choreography uses direct RPC calls
- Choreography is only applicable to read-heavy workloads
Correct answer: In choreography, each service reacts to events autonomously without a central controller
In choreography, services react to domain events published by other services without a central orchestrator, leading to decentralized and loosely coupled coordination.
Question 5: The Backend for Frontend (BFF) pattern solves which architectural problem?
- Reducing database query latency for backend services
- Tailoring API interfaces to the specific needs of each client type (e.g., mobile vs. web) (Correct answer)
- Sharing a single codebase between frontend and backend teams
- Enforcing strict data validation at the service boundary
Correct answer: Tailoring API interfaces to the specific needs of each client type (e.g., mobile vs. web)
BFF creates a dedicated backend for each type of frontend client, allowing each to evolve independently with an API optimized for its unique needs.
Question 6: Which pattern ensures that a message is reliably published to a message broker even when the publishing service and broker are temporarily unavailable?
- Dead Letter Queue
- Transactional Outbox Pattern (Correct answer)
- Request-Reply Pattern
- Competing Consumers Pattern
Correct answer: Transactional Outbox Pattern
The Transactional Outbox writes the event to an outbox table in the same database transaction as the business operation, and a relay process then publishes it to the broker.
Question 7: In microservices, the Sidecar pattern deploys a helper process alongside each service instance. What is a typical use case?
- Replacing the primary service during blue-green deployments
- Handling cross-cutting concerns like logging, monitoring, and service mesh proxying (Correct answer)
- Storing shared configuration in a distributed cache
- Scaling the primary service horizontally based on CPU load
Correct answer: Handling cross-cutting concerns like logging, monitoring, and service mesh proxying
A sidecar container handles infrastructure concerns (TLS termination, logging, metrics collection) transparently, so the main service stays focused on business logic.
Which microservices pattern coordinates a sequence of local transactions across multiple services using events or messages to maintain data consistency?