Architecture Styles and Patterns: A Practical Guide
Compare layered, hexagonal, event-driven, and service architectures using boundaries, deployment needs, failure modes, and a concrete selection method.
Architecture styles define system-wide boundaries, while patterns address narrower problems such as reliable message delivery. This guide compares layered, hexagonal, modular monolith, microservices, and event-driven designs through team ownership, data boundaries, deployment needs, and operational costs. It applies those trade-offs to an order-management system, then shows how to record the decision, enforce module boundaries, and learn from production failures.
Architecture Styles and Patterns: A Practical Guide
Introduction
When checkout saves an order and sends a receipt, decide whether receipt delivery belongs in the request or can happen later. A small team that releases one application may be well served by a modular monolith with an outbox. If several independent consumers need the order event and can work asynchronously, an event-driven boundary may be worth its added operational cost.
The comparisons below start with team and product constraints, then use the order flow to show what changes.
When to use a named style
Use a named style when it helps a team agree on boundaries, dependency direction, deployment units, or communication rules. Hexagonal architecture can keep domain policy independent from a database adapter; event-driven design lets consumers react to durable facts.
Avoid forcing every system into one style. A small internal tool may need a layered structure. A product can combine styles: a modular monolith with ports and adapters inside important modules, plus asynchronous events for a few workflows. If a pattern adds queues or coordination without protecting a requirement, its cost may outweigh its benefit.
Core concepts
An architecture style constrains system organization. Layered architecture separates presentation, domain logic, and persistence. Hexagonal architecture places application policy behind ports, with adapters for databases and APIs. Event-driven architecture communicates through events; microservices split a system into independently deployable services.
A pattern is a reusable response to a narrower design problem. The outbox, circuit breaker, and saga patterns can appear within several styles. Each still has costs.
Keep three boundaries distinct:
- Code boundary: modules and dependency rules.
- Data boundary: who owns each record or schema.
- Deployment boundary: what can be released and scaled independently.
These boundaries can line up, but they do not have to. A modular monolith can enforce code and data ownership while shipping as one deployment. Microservices add network boundaries and operational work.
flowchart TD
Need[Product and team constraints] --> Boundary[Choose code and data boundaries]
Boundary --> Style[Select an architecture style]
Style --> Pattern[Apply focused patterns where needed]
Pattern --> Validate[Test quality goals and failure behavior]
Validate -->|New evidence| Need
A practical selection method
Start with the constraints, then compare two shapes for the same checkout flow. For a small team that owns both order creation and receipts, a modular monolith is often easier to run. A service split becomes more attractive when separate teams need independent releases and can support the extra production machinery.
| Constraint | Modular monolith | Order service plus event consumer |
|---|---|---|
| Team ownership | One team owns checkout and receipts. | Separate teams own order writes and receipt delivery, with clear on-call owners. |
| Data boundaries | The orders module owns writes; one transaction saves the order and outbox row. | The order service owns its database; the consumer tracks handled event IDs. |
| Deployment independence | Modules release together. | Services release separately; the event schema must remain compatible. |
| Operational capacity | One application, database, and worker. | Broker, retries, dead-letter handling, schema changes, and tracing need on-call support. |
Same order, two designs
Inside a modular monolith: POST /checkout calls the orders module. One database transaction saves the order and an outbox item. A worker reads the item and sends the receipt. If the email provider is down, checkout can still return success; the receipt waits for a retry. Order ownership stays local, and the team has one deployment to diagnose.
Across a service boundary: POST /checkout calls the order service, which commits the order and an outbox item in its own database. A relay publishes OrderPlaced; a separately deployed consumer sends the receipt and records the event ID so redelivery does not repeat the email. If the broker or consumer is unavailable, checkout can still succeed while the receipt is delayed. The boundary allows independent releases, but the team must monitor backlog, retries, and dead letters.
The outbox pattern guide explains the durable handoff. Record the chosen boundary and the condition that would change it in an architecture decision record. Then turn rules such as “only orders writes order records” into executable architecture fitness functions.
Enforcing modular boundaries
A modular monolith only protects the team from service-level coordination if its modules have rules that code review and automation can check. A folder named orders is not a boundary when other modules can import its repositories or write its tables directly.
Start with a small public API for each module. For example, checkout can call Orders.placeOrder() and receive an order identifier, while only the orders module can change order records. Other modules should not import its persistence code. If a workflow needs another module’s data, expose a query or publish a domain event instead of reaching into its tables.
Turn those rules into checks: reject imports from another module’s internal packages, test that only the owner writes each table, and flag cycles in the dependency graph. Run the checks in CI. When a rule blocks a real use case, review the boundary and the use case together; do not create a general-purpose shared module just to make the check pass. The modular monolith guide goes deeper on module ownership and implementation.
This gives a team evidence before it considers a service split. If a module can be changed and tested behind a stable API, a later extraction has a clearer seam. If it cannot, a network boundary will make the same coupling slower and harder to debug.
Production failure scenarios
Scenario 1: A timeout leaves an order half-complete
What happened: During a checkout traffic spike, the order service saved an order and then called payment and inventory synchronously. The payment call timed out after the provider had authorized the charge, so a retry created a second authorization while inventory still showed stock available.
Root cause: The workflow crossed service boundaries without a durable record of progress or an idempotency key shared with the payment operation.
Impact: Some customers saw a failed checkout despite a valid authorization; support had to reconcile duplicate charges and unreserved stock.
Mitigation: Give each checkout attempt a stable idempotency key, persist workflow state, set deadlines, and define compensating actions for authorization or reservation failures. A saga can coordinate the steps; the event sourcing overview discusses durable state histories that can support such workflows.
Scenario 2: A schema change breaks a supposed service boundary
What happened: The catalog team renamed a product table column during a deployment. The checkout service still queried that table directly, so checkout requests failed until the old column was restored.
Root cause: Both services shared a database schema without a migration contract, despite being deployed independently.
Impact: A catalog release caused checkout errors, and the teams could not deploy on their own schedules.
Mitigation: Make one service the writer and owner of each data model, expose reads through an API or published event, and use expand-and-contract migrations when consumers must move gradually. Add a dependency check so direct access to another module’s tables is visible before release.
Scenario 3: A redelivered event sends duplicate work
What happened: A notification consumer sent an email, then crashed before acknowledging the broker message. The broker redelivered it, and the customer received the same receipt twice.
Root cause: The consumer performed a non-idempotent side effect before recording that the event had been handled.
Impact: Customers got duplicate messages, and operators could not distinguish a replay from a new notification using the logs.
Mitigation: Give each event a stable identifier, record processed identifiers, and make the handler safe to retry. Track retry counts and dead-letter messages, and include the event ID in logs and traces. Delivery guarantees alone do not make the business operation happen exactly once.
Observability checklist
- Record request and message correlation identifiers.
- Measure latency, error rate, saturation, and queue age for each deployable unit.
- Track consumer retries, dead-letter counts, and event processing lag.
- Alert on user-facing symptoms and stuck workflows, not only process health.
- Keep dashboards organized around capabilities and ownership.
Security and compliance
Architecture boundaries should enforce authorization and data access. Validate permissions at service entry points, restrict database credentials to the owning component, and keep secrets out of logs. For event systems, classify payloads, minimize personal data, and set retention rules. Confirm jurisdiction-specific requirements with security and compliance owners.
Common pitfalls
- Choosing microservices to solve code organization; packages and modules may be enough.
- Calling a system “event-driven” while events are undocumented internal callbacks.
- Letting every layer depend on every other layer.
- Creating generic abstractions before a second implementation or meaningful test seam exists.
- Splitting a domain by database tables rather than business ownership and change patterns.
Quick checklist
- Name the product, team, data, and operational constraints first.
- Decide which boundaries must be enforced in code, data, and deployment.
- Compare at least two viable designs and write down the costs of each.
- Apply patterns to specific problems; avoid adopting a whole architecture bundle by default.
- Revisit the decision when constraints change or evidence shows the boundary is failing.
Interview questions
A style constrains the system's broad organization, such as layers or independently deployed services. A pattern solves a more focused recurring problem, such as atomically recording a message with a database update. Patterns can be used within multiple styles.
When a capability has a stable boundary and independent deployment, scaling, or ownership produces enough value to pay for network communication and operational overhead. High traffic alone does not prove that a service split is needed.
Yes. Hexagonal architecture describes dependency direction around application policy. It does not require separate processes. A monolith can use ports and adapters while sharing a deployment unit.
Further reading
- Martin Fowler: Microservices, trade-offs and organizational context for service architecture.
- C4 model, a notation for describing systems at useful levels of detail.
- Microsoft architecture styles, reference guidance for common application and system styles.
- Continue with the quality attributes and architecture trade-offs guide and the architecture decision records guide.
- Review separation of concerns and module boundaries and the layered architecture guide for two ways to make code boundaries explicit.
Conclusion
For this checkout, keep the order write local and place receipt delivery behind an outbox. Split out a receipt consumer when a separate team needs independent releases and can operate the broker, retries, and monitoring. Put that trigger in the decision record, then enforce the order module’s write boundary in CI.
Category
Related Posts
Quality Attributes and Architecture Trade-offs
Turn goals like reliability, security, and performance into measurable scenarios, then compare architectural choices with explicit costs and constraints.
Backend Separation of Concerns and Module Boundaries
Learn how to set backend module boundaries, keep dependencies pointed in one direction, and avoid coupling that makes routine changes risky.
Software Architecture Patterns Roadmap
Learn software architecture patterns from core reasoning and application styles through distributed design, trade-offs, and production validation.