← Back to Index

4. Architecture Patterns

Multi-Tier Architecture

Also called n-tier architecture, this pattern separates an application into logical layers:

# 3-Tier Request Flow
Browser (Presentation) → sends HTTP request
Load Balancer → routes to Application Server
Application Server (Business Logic) → processes request
Application Server queries Database (Data Tier)
Response flows back through the same chain

Microservices Architecture

Microservices decompose an application into small, independently deployable services, each responsible for a specific business capability.

Microservices architecture with API gateway, individual services, databases, and event bus

Key characteristics:

Microservices vs Monolith

FactorMonolithMicroservices
DeploymentSingle deploy unitIndependent deploys
ScalingScale entire appScale per service
DevelopmentSimple to startComplex coordination
TestingEnd-to-end easierContract testing needed
Team autonomyLow (shared codebase)High (per-team ownership)

Event-Driven Architecture

Components communicate through events — messages published to an event bus. Producers emit events without knowing who consumes them. Consumers subscribe to relevant events.

# Event-Driven Flow
User places order → Order Service publishes "order.created" event
Event Bus (Kafka/RabbitMQ) distributes the event
Inventory Service consumes → reserves stock
Notification Service consumes → sends confirmation email
Analytics Service consumes → records order data

Benefits: Loose coupling, asynchronous processing, excellent for workflows spanning multiple services.

Challenges: Event ordering, exactly-once processing, debugging event chains, eventual consistency.

Service Mesh

A service mesh (e.g., Istio, Linkerd) adds a sidecar proxy to each service instance to handle service-to-service communication, observability, and security. It separates these concerns from application code.

CQRS (Command Query Responsibility Segregation)

Separates read and write operations into different models. Writes go through commands; reads go through separate queries — possibly using different data stores or schemas optimized for each purpose.

Exercise: You are designing the backend for an e-commerce platform. Identify which parts would benefit from microservices (e.g., product catalog, checkout, payments) and which might remain monolithic. Draw the service boundaries and describe how they communicate.