8 Essential Software Architecture Patterns and When to Use Them
This article explains eight common software architecture patterns—from single‑database apps to microservices, caching, sharding, elastic scaling and multi‑datacenter deployment—detailing their designs, typical use cases, advantages, drawbacks, and practical implementation steps.
Architecture Overview
Software architecture provides the structural skeleton of a system, defining how components interact, where data is stored, and how scalability, availability, and performance are achieved.
Eight Common Architectural Design Patterns
1. Single‑Database Single‑Application Pattern
Typical for prototypes or very small products: one relational database, one business‑logic layer, and one admin interface.
Advantages : Simple code base, fast development, low operational overhead.
Disadvantages : Poor performance under load, no high‑availability, limited scalability.
2. Content Distribution Pattern
Static assets (images, CSS, JS) are stored in an object storage service (OSS) and served through a CDN. A typical request flow for an image upload is:
User selects a local file.
Application uploads the file to OSS and receives a URL.
The URL is persisted in the business database.
When the image is displayed, the client requests the URL.
DNS resolves the URL to the nearest CDN edge node.
The edge node returns the cached copy.
Advantages : Fast download, reduced backend storage pressure, bandwidth savings.
Disadvantages : OSS/CDN cost, consistency latency, best suited for medium‑scale apps.
3. Query Separation Pattern
Read and write traffic are split using a master‑slave (primary‑replica) database topology, often combined with a full‑text search engine such as Elasticsearch.
Advantages : Offloads read load from the primary, near‑unlimited read capacity, better overall latency.
Disadvantages : Data replication lag, added complexity for consistency guarantees.
Typical workflow for full‑text search:
Business data is written to the primary database.
An asynchronous process indexes the same record into Elasticsearch.
Search queries are sent directly to Elasticsearch; results are merged with relational data if needed.
4. Microservice Pattern
The monolith is decomposed into independent services. Each service owns its own database, cache, and optional search engine, and communicates via RPC (e.g., gRPC, Thrift) or asynchronous messaging (e.g., Kafka, RabbitMQ).
Advantages : High performance, independent scaling per domain, better fault isolation.
Disadvantages : Increased operational complexity, need for strong governance, risk of over‑splitting.
Key considerations:
Define clear service boundaries (Conway’s Law).
Expose functionality through versioned APIs.
Use a service mesh or API gateway for routing, security, and observability.
5. Multi‑Level Cache Pattern
Caching is applied at three layers to absorb read traffic before it reaches the database:
Client‑side cache : Browser storage, mobile local DB, or in‑process memory.
API‑gateway cache : Nginx cache module, Lua+Redis, or dedicated edge cache.
Backend service cache : Redis, Memcached, or in‑process LRU caches.
Advantages : Handles massive read bursts, dramatically reduces backend load.
Disadvantages : Cache invalidation complexity, risk of cache‑miss‑induced traffic spikes (snowball effect).
6. Sharding (Split‑Database‑Split‑Table) Pattern
Large tables are horizontally partitioned across multiple databases and tables to reduce per‑node pressure.
Advantages : Lower per‑table I/O, improved query latency.
Disadvantages : Distributed transaction complexity, extensive code refactoring for routing logic.
Implementation steps:
Identify high‑traffic tables.
Define a sharding key (e.g., user_id).
Provision N database instances (or hosts) and create M tables per instance.
Implement a routing layer that maps a sharding key to a specific host → database → table tuple.
Handle cross‑shard queries via aggregation or redesign.
7. Elastic Scaling Pattern
Compute resources are pooled (VMs or containers). An autoscaler monitors metrics such as CPU, memory, and network I/O and adds or removes instances accordingly.
Advantages : Cost‑effective resource usage, automatic handling of traffic spikes.
Disadvantages : Requires applications to be horizontally stateless, adds operational overhead (monitoring, scaling policies).
Typical autoscaling loop:
while true:
metrics = collect_metrics()
if metrics.cpu > 80% for 2m:
scale_out()
elif metrics.cpu < 30% for 5m:
scale_in()
sleep(30)8. Multi‑Datacenter (Multi‑Region) Pattern
Services are deployed in several geographic regions. Intelligent DNS (or anycast) resolves user requests to the nearest region, providing low latency and high availability.
Advantages : Reduced latency for global users, fault isolation across regions.
Disadvantages : Data synchronization across regions, consistency management, routing complexity.
Typical request flow:
User accesses https://service.example.com.
Smart DNS resolves the domain to the IP of the nearest datacenter.
The request is served by that region’s services.
Data changes are replicated to other regions using asynchronous pipelines (e.g., change‑data‑capture + Kafka).
Summary of Trade‑offs
Each pattern solves a specific set of problems but introduces its own operational concerns. Selecting a pattern requires evaluating current load, growth expectations, team expertise, and budget constraints. In practice, systems often combine several patterns—for example, a microservice architecture with query separation, multi‑level caching, and elastic scaling—to achieve the desired balance of performance, scalability, and reliability.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect's Guide
Dedicated to sharing programmer-architect skills—Java backend, system, microservice, and distributed architectures—to help you become a senior architect.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
