LearningTree

Examples & Case Studies

Reference architectures, the distinction between styles, patterns, and design patterns, real-world case studies, and migration strategies โ€” architecture learned through practice.

01
Chapter One ยท Terminology

Architectural Styles vs. Patterns vs. Design Patterns

These three terms are often confused. They operate at different levels of scope โ€” from the shape of the entire system down to code-level solutions within a single component.

๐Ÿ™๏ธ

Architectural Style

  • Defines the overall shape and vocabulary of the entire system
  • Client-server, layered, event-driven, REST, pipe-and-filter
  • Analogy: city planning
๐Ÿ 

Architecture Pattern

  • Solves a specific recurring problem at the system/subsystem level
  • MVC, CQRS, Saga, Circuit Breaker, Strangler Fig
  • Analogy: building design
๐Ÿงฑ

Design Pattern

  • Solves a code-level design problem within a component
  • Strategy, Observer, Factory, Decorator, Singleton
  • Analogy: interior design
Scope Hierarchy โ€” Style โ†’ Pattern โ†’ Design Pattern
ARCHITECTURAL STYLE Entire system shape Client-Server ยท Layered Event-Driven ยท REST ๐Ÿ™๏ธ City Planning ARCHITECTURE PATTERN System / subsystem level MVC ยท CQRS ยท Saga Circuit Breaker ยท Strangler Fig ๐Ÿ  Building Design DESIGN PATTERN Code / class level Strategy ยท Observer Factory ยท Decorator ๐Ÿงฑ Interior Design
You can mix styles and patterns โ€” e.g., a microservices style using the CQRS pattern with the Strategy design pattern inside each service.
๐Ÿ“‹ Chapter 1 โ€” Summary
  • Architectural Style โ€” defines the overall shape and vocabulary of the entire system (city planning)
  • Architecture Pattern โ€” a proven solution for a recurring problem at the system/subsystem level (building design)
  • Design Pattern โ€” a code-level solution within a single component (interior design)
  • Wider scope โ†’ narrower scope: Style โ†’ Pattern โ†’ Design Pattern
  • You can combine styles and patterns freely within one system
02
Chapter Two ยท Reference Architectures

Common Reference Architectures

Reference architectures are proven blueprints for common application types. They provide a starting point โ€” not a rigid prescription โ€” that you adapt to your specific requirements and constraints.

๐ŸŒ

3-Tier Web Application

  • Presentation โ†’ Application โ†’ Data
  • Stateless app tier enables horizontal scaling
๐Ÿ“จ

Event-Driven Architecture

  • Components communicate through events via a broker
  • Strong decoupling, eventual consistency
โš™๏ธ

Batch Processing (ETL)

  • Extract โ†’ Transform โ†’ Load pipelines
  • Pipes-and-filters pattern for data processing
๐Ÿ“ฑ

Backend for Frontend (BFF)

  • Each client type gets its own tailored backend
  • Prevents bloated "one API for all" syndrome
3-Tier Web Application

The most common architecture for business applications โ€” a presentation tier, a stateless application tier, and a data tier.

3-Tier Architecture โ€” Presentation โ†’ Application โ†’ Data
Presentation Browser / Mobile App React ยท Angular ยท Flutter ๐ŸŒ CDN-served static assets HTTPS Application Business Logic (Stateless) REST API ยท GraphQL โš–๏ธ Load balanced TCP Data Persistence Layer PostgreSQL ยท MongoDB ยท Redis ๐Ÿ”„ Replicated
Quality FocusArchitectural Tactic
ScalabilityStateless app tier โ†’ horizontal scaling behind a load balancer
AvailabilityMultiple app instances, database replication, health checks
SecurityHTTPS, authentication middleware, input validation, CORS
PerformanceCDN for static assets, caching layer (Redis), connection pooling
Event-Driven Architecture

Components communicate through events โ€” immutable facts about things that happened. Producers publish events to a broker; consumers subscribe and react independently.

Event-Driven โ€” Producers โ†’ Event Bus โ†’ Consumers
Order Svc producer User Svc producer ๐Ÿ“จ Event Bus Kafka ยท RabbitMQ ยท SNS+SQS orders.* ยท users.* ยท payments.* Notification Svc Analytics Svc Inventory Svc Producers don't know consumers โ€” new consumers subscribe without changing producers
Quality FocusArchitectural Tactic
Loose CouplingProducers don't know consumers; events are immutable facts
ScalabilityConsumers scale independently based on throughput needs
ResilienceMessages persist in broker even if a consumer is temporarily down
ConsistencyEventual consistency โ€” requires careful event ordering & idempotency
๐Ÿ“‹ Chapter 2 โ€” Summary
  • 3-Tier Web: Presentation โ†’ stateless application โ†’ data; most common reference architecture
  • Event-Driven: Components communicate through events via a broker โ€” loose coupling, eventual consistency
  • Batch (ETL): Extract โ†’ Transform โ†’ Load pipelines using the pipes-and-filters pattern
  • BFF: Each client type (web, mobile) gets its own tailored backend API
  • Reference architectures are starting points โ€” adapt them to your specific constraints
03
Chapter Three ยท Architecture Spectrum

Monolith vs. Microservices โ€” The Spectrum

This is not a binary choice. The reality is a spectrum โ€” from a single deployable monolith all the way to hundreds of fine-grained microservices. Start simple and evolve when you have a clear need.

The Monolith-to-Microservices Spectrum
Monolith Single deployable Simple operations Modular Monolith Clean internal modules Single deployment Service-Based Few coarse services (3โ€“8 services) Microservices Many small services (50+ services) โœ“ Start here for most projects โ€” move right ONLY when you have a clear need โ† Simpler operations ยท Fewer failure modes ยทยทยทยทยทยทยทยทยทยท Independent deployment ยท Independent scaling โ†’
Key principle: Start with a well-structured modular monolith. Extract services only when you have clear domain boundaries, team boundaries, and a genuine need for independent deployment. You can always extract later โ€” you can't easily merge back.
๐Ÿ“‹ Chapter 3 โ€” Summary
  • Monolith vs. microservices is a spectrum, not a binary choice
  • Start with a modular monolith โ€” extract services only when you have a clear need
  • Moving right on the spectrum adds operational complexity (CI/CD, monitoring, tracing)
  • You can always extract later โ€” you can't easily merge back
04
Chapter Four ยท Real-World Examples

Case Studies

Architecture is best learned by studying how others have solved real problems โ€” and by understanding why they made specific trade-offs. Every decision has consequences.

Case Study โ€” E-Commerce Platform

An e-commerce platform (simplified Amazon). Here's how architecture decisions map to quality requirements and trade-offs.

E-Commerce Domain Decomposition โ€” Each Service Owns Its Data
๐Ÿ“ฆ Catalog Products ยท Search read-heavy ๐Ÿ›’ Order Create ยท Track ACID consistent ๐Ÿ“Š Inventory Stock levels event-sourced ๐Ÿ’ณ Payment Stripe ยท PayPal PCI isolated ๐Ÿ“ง Notify Email ยท SMS ยท Push fire-and-forget ๐Ÿ“จ Kafka Event Bus โ€” OrderPlaced ยท PaymentProcessed ยท StockReserved Each service owns its own database โ€” no shared databases Services communicate ONLY through events or explicit API calls Each service maps to one bounded context (DDD)
DecisionRationaleTrade-off
Microservices5 teams, independent deployment, different scaling needsOperational complexity; CI/CD, monitoring, tracing investment
Kafka Event BusLoose coupling; independent evolution; audit trailEventual consistency; harder debugging; schema evolution
CQRS for Catalog10:1 read-to-write ratio; different data modelsTwo data stores to maintain; sync lag
Saga for Order flowNo distributed transactions; each service owns its dataCompensating transactions on failure; complex failure modes
Case Study โ€” Legacy Modernization with Strangler Fig

A 15-year-old monolithic application needs modernization. Rewriting from scratch is too risky. Instead, use the Strangler Fig pattern โ€” gradually replace pieces while the system stays fully operational.

Strangler Fig โ€” Gradual Migration (Always in a Working State)
Phase 1: Start Legacy Monolith 100% of traffic Phase 2: Extract Legacy (~70%) New Service (~30%) Phase 3: Complete Legacy (tiny remnant) New Services ~95% of traffic Route traffic gradually from legacy to new services โ€” zero big-bang risk, always in a working state
How It Works
  • Put a proxy/facade in front of the monolith that routes all traffic
  • Extract one capability at a time as a new service behind the proxy
  • Route traffic gradually โ€” feature flags, canary releases
  • Repeat until the legacy monolith is empty
Lessons Learned
  • Start with a monolith โ€” extract only when domain and team boundaries are clear
  • Invest in observability early โ€” distributed tracing, centralized logging, metrics
  • Event schema evolution is hard โ€” use a schema registry from day one
  • Test failure modes โ€” chaos engineering is not optional for distributed systems
๐Ÿ“‹ Chapter 4 โ€” Summary
  • E-Commerce case study: domain-driven decomposition, event bus, CQRS, Saga โ€” every decision is a trade-off
  • Strangler Fig: gradual migration from legacy โ€” always in a working state, zero big-bang risk
  • Named after a tropical fig that grows around a host tree, eventually replacing it entirely
  • Every architecture decision is a trade-off โ€” document the rationale, not just the choice
Summary โ€” Examples & Case Studies at a Glance
01 ยท Terminology

Styles vs Patterns

  • Style = system shape (city planning)
  • Pattern = subsystem solution (building design)
  • Design Pattern = code-level (interior design)
02 ยท Reference Architectures

Proven Blueprints

  • 3-Tier: stateless app tier โ†’ horizontal scaling
  • Event-Driven: loose coupling via broker
  • ETL & BFF for specialized use cases
03 ยท Spectrum

Monolith โ†’ Microservices

  • It's a spectrum, not a binary choice
  • Start modular monolith, extract when needed
  • You can extract later; can't merge back
04 ยท Case Studies

Real-World Lessons

  • Domain decomposition with event bus
  • Strangler Fig for gradual migration
  • Every decision is a trade-off โ€” document why
Software Architecture Foundation ยท Examples & Case Studies ยท LearningTree ยท 2026