CPSA Architectural Patterns and Styles 2 — Questions and Answers
Question 1: In Hexagonal Architecture (Ports and Adapters), what is the primary role of a 'port'?
- A database connection pool
- An interface defining how the application interacts with the outside world (Correct answer)
- A network socket for inter-service communication
- A deployment pipeline stage
Correct answer: An interface defining how the application interacts with the outside world
A port is an interface (API or SPI) that defines how the core domain communicates with external actors, keeping the domain independent of specific technologies.
Question 2: Which architectural pattern separates the responsibility of reading data from writing data into distinct models?
- Repository Pattern
- CQRS (Command Query Responsibility Segregation) (Correct answer)
- Active Record
- Data Mapper
Correct answer: CQRS (Command Query Responsibility Segregation)
CQRS splits the application into a Command side (writes/mutations) and a Query side (reads), allowing each to be optimized independently.
Question 3: Event Sourcing stores application state as a sequence of events. What is the main advantage of this approach?
- Reduced storage requirements
- A complete audit trail and the ability to reconstruct past states (Correct answer)
- Faster read performance out of the box
- Simplified query logic
Correct answer: A complete audit trail and the ability to reconstruct past states
Because every state change is recorded as an immutable event, you can replay the event log to reconstruct the system state at any point in time.
Question 4: In the Strangler Fig pattern, what happens to the legacy system over time?
- It is immediately replaced in a big-bang migration
- New functionality wraps and gradually replaces the old system until the legacy is removed (Correct answer)
- It is kept running in parallel indefinitely
- It is refactored in place without deploying new services
Correct answer: New functionality wraps and gradually replaces the old system until the legacy is removed
Like a strangler fig vine, new services incrementally take over functionality from the legacy system until the old system can be decommissioned.
Question 5: Which of the following best describes the Pipe-and-Filter architectural style?
- Components communicate through shared database tables
- Processing steps (filters) are connected by data channels (pipes) enabling sequential transformation (Correct answer)
- Services register themselves in a central registry for discovery
- Each request is handled by a dedicated thread pool
Correct answer: Processing steps (filters) are connected by data channels (pipes) enabling sequential transformation
In Pipe-and-Filter, independent filter components process data and pass results through pipes, enabling composable, reusable processing chains.
Question 6: A system uses the Blackboard architectural pattern. Which scenario best fits this style?
- A REST API exposing CRUD operations for a mobile app
- Multiple specialized subsystems collaborate to incrementally solve a complex problem like speech recognition (Correct answer)
- A load balancer distributing requests across identical server instances
- A caching layer placed in front of a relational database
Correct answer: Multiple specialized subsystems collaborate to incrementally solve a complex problem like speech recognition
The Blackboard pattern suits problems where multiple knowledge sources (specialists) contribute partial solutions to a shared data store until a complete solution emerges.
Question 7: In Service-Oriented Architecture (SOA), what is the purpose of an Enterprise Service Bus (ESB)?
- To host microservices in containers
- To mediate, transform, and route messages between loosely coupled services (Correct answer)
- To provide a UI shell aggregating multiple applications
- To enforce API rate limits on external consumers
Correct answer: To mediate, transform, and route messages between loosely coupled services
An ESB acts as middleware that handles routing, protocol transformation, message translation, and orchestration between services in an SOA.
In Hexagonal Architecture (Ports and Adapters), what is the primary role of a 'port'?