Architectural Styles and Patterns
Compare layered, modular monolith, microservices, event-driven, and other styles, and select one using drivers and context.
Introduction
An architectural style is a recurring way of organizing a system: its elements, their relationships, and constraints on how they interact. Styles provide a vocabulary and known trade-offs, so you do not design from nothing.
The goal is not to pick the most fashionable style. It is to pick the simplest style that satisfies your drivers and fits your team, and to know what you are trading away.
Learning Objectives
- Describe the main architectural styles and their strengths and weaknesses.
- Distinguish a style from a pattern and from a technology.
- Match styles to quality attribute drivers and team context.
- Recognize common mistakes such as premature distribution.
- Use AI to compare options without being swayed by buzzwords.
1. Style, Pattern, Technology
| Term | Meaning | Example |
|---|---|---|
| Style | Overall organization of the system | Microservices |
| Pattern | Reusable solution to a recurring design problem | Circuit breaker, CQRS, outbox |
| Technology | A concrete tool or product | A particular database or queue |
Choose style first, then patterns, then technology. Starting with technology produces architecture shaped by a product’s marketing.
2. Common Styles
Layered (n-tier). Presentation, business logic, data access. Simple, widely understood, easy to start. Risk: layers become a dumping ground, changes cut across all layers, and the business logic gets entangled with data access.
Modular monolith. One deployable unit, internally divided into modules with explicit boundaries and interfaces. Strong cohesion, simple operations, one transaction boundary, and a path to extract services later. Risk: boundaries erode without discipline and tooling.
Microservices. Independently deployable services, each owning its data, organized around business capabilities. Enables independent scaling and team autonomy. Costs: distributed systems complexity, network failure, data consistency, observability, deployment automation, and substantial operational maturity.
Event-driven. Components communicate by publishing and consuming events. Decouples producers from consumers, absorbs bursts, supports asynchronous workflows. Costs: harder reasoning about flow, eventual consistency, debugging, and event schema evolution.
Hexagonal / ports and adapters (clean architecture). The domain core is independent of infrastructure; adapters connect it to databases, APIs, UIs. Improves testability and replaceability. Cost: more indirection and up-front structure.
Pipeline / pipes and filters. Data flows through processing stages. Good for import and transformation workflows. Needs care with error handling and back pressure.
Client-server and API-based SPA + backend. Common for web products; consider how rendering, state, and security are split.
Serverless / function-based. Managed execution of small functions. Low operations for spiky workloads. Costs: cold starts, limits, vendor coupling, and difficulty reproducing locally.
Styles combine. A modular monolith with an asynchronous pipeline for import and background workers is common and practical.
3. Matching Styles to Drivers
| If the drivers are… | Consider |
|---|---|
| Small team, fast delivery, moderate scale | Modular monolith, hexagonal inside |
| Independent scaling of very different workloads | Separate the heavy workload as its own process or service |
| Bursty, long-running background processing | Queue plus workers (event-driven in part) |
| Many teams needing independent release cycles | Microservices, if operational maturity exists |
| High need to swap infrastructure or test domain logic in isolation | Hexagonal |
| Strict isolation requirements per tenant | Evaluate tenancy model before the style |
Be wary of copying a large company’s architecture. Their drivers (hundreds of engineers, global scale) are not yours.
4. The Premature Distribution Trap
Splitting a system into services early replaces function calls with network calls, transactions with eventual consistency, and local debugging with distributed tracing. Teams under about ten engineers rarely have the capacity to absorb that cost, and the benefits (independent deployment by independent teams) do not yet exist.
A sound default for many early-stage products: start as a well-structured modular monolith, with clear module boundaries and asynchronous processing for long tasks, and extract a component only when a specific driver justifies it. This is a guideline, not a law. Heavy data residency isolation, regulatory separation, or radically different scaling needs can justify separation sooner.
5. Applying It to SignalDesk
Drivers from Lesson 2 (illustrative): privacy and isolation, reliable import, search performance, small team, low initial cost.
Candidate options:
| Option | Fit | Main risk |
|---|---|---|
| A. Modular monolith + background worker + relational DB + search index | Strong fit for team and scale; simple operations | Module boundary erosion; search load shares resources |
| B. Microservices (import, themes, search, summaries) | Independent scaling | Heavy operational load; consistency across services |
| C. Serverless functions + managed services | Low operations for bursts | Vendor lock-in; complex local development; limits on long imports |
For a four-person team with moderate scale, option A is the likely candidate, with the import worker as a separately runnable process. Treat this as a hypothesis to test in later lessons through trade-off analysis, not as a conclusion.
6. Patterns to Know
| Pattern | Problem it addresses |
|---|---|
| Repository | Separates domain logic from data access |
| Queue / worker | Moves slow work out of the request cycle |
| Outbox | Reliably publish events along with a database change |
| CQRS | Separate models for reading and writing when needs differ |
| Circuit breaker | Stop calling a failing dependency |
| Retry with backoff | Handle transient failures |
| Idempotent receiver | Make repeated messages safe |
| Strangler | Gradually replace parts of a legacy system |
| Anti-corruption layer | Isolate your model from an external one |
Learn a pattern’s problem and cost before using it. Applying patterns without a problem produces complexity without benefit.
7. Use AI to Compare Options
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Act as an experienced software architect who is skeptical of hype.
Context:
- Drivers and quality scenarios: [paste top drivers]
- Constraints: [paste]
- Team: [size, skills, operations capacity]
- Expected scale in 12 months: [numbers, mark as assumption]
Compare three architectural styles for this system.
For each:
1. How it addresses each top driver (good / partial / poor).
2. Operational and cognitive cost for this team.
3. Main risks and what would make it the wrong choice.
4. Conditions under which we should migrate away from it.
Finish with a recommendation and the strongest argument against it.
Do not assume capabilities of specific vendor products.
Ask the AI to argue for the option it rejected. If it cannot give a convincing case, you understand the trade-off better. If it cannot explain how a style satisfies a particular driver, do not accept that claim.
8. Practical Exercise
For SignalDesk (or your own system):
- Write a one-page comparison of at least three styles against your top five drivers, using a scoring table with written reasons, not only numbers.
- Choose a preferred style and write the conditions under which you would change your mind.
- List the patterns you expect to use, each with the problem it solves.
- Record your choice as a draft decision (formalized as an ADR in Lesson 10).
Verification
You are ready to continue when:
- Your comparison references specific drivers, not general merits.
- The chosen style fits the team’s capacity and scale assumptions.
- Each pattern is linked to a concrete problem.
- You have written the conditions that would invalidate the choice.
Key Takeaways
- Choose style by drivers and context, not fashion.
- A modular monolith is a strong default for small teams, with deliberate extraction later.
- Distribution has real costs; add it when a driver demands it.
- AI can compare styles, but it needs your drivers, and its claims need checking.
What’s Next?
With a style chosen, we design the system itself: containers, components, boundaries, and the key runtime flows.