references/design-patterns.md · 24000
tables or services are expensive, slow, and sometimes impossible in NoSQL stores.
When to use:
- Read queries require joining data across multiple stores or tables
- The read pattern is well-known and relatively stable
- You can tolerate a short delay between a write and its appearance in the view
- You want to offload complex query logic from the application tier
WAF Pillars: Performance Efficiency
Related patterns: CQRS, Event Sourcing, Index Table, Cache-Aside
28. Messaging Bridge
Build an intermediary to enable communication between messaging systems that are otherwise incompatible, due to protocol, format, or infrastructure differences.
Problem: Organizations may operate multiple messaging systems (RabbitMQ, Azure Service Bus, Kafka, legacy MQ). Applications bound to different brokers cannot exchange messages natively, creating data silos and duplicated effort.
When to use:
- You need to integrate systems that use different messaging protocols or brokers
- A migration from one messaging platform to another must be gradual
- You want to decouple producers and consumers from a specific messaging technology
- Interoperability between cloud and on-premises messaging is required
WAF Pillars: Cost Optimization, Operational Excellence
Related patterns: Anti-Corruption Layer, Publisher/Subscriber, Strangler Fig
29. Pipes and Filters
Decompose a task that performs complex processing into a series of separate elements that can be reused.
Problem: Monolithic processing pipelines are difficult to test, scale, and reuse. A single stage's failure brings down the entire pipeline. Different stages may have different scaling needs that cannot be addressed independently.
When to use:
- Processing can be broken into discrete, independent steps
- Different steps have different scaling or deployment requirements
- You want to reorder, add, or remove processing stages without rewriting the pipeline
- Individual steps should be independently testable and reusable
WAF Pillars: Reliability
Related patterns: Competing Consumers, Queue-Based Load Leveling, Choreography
30. Priority Queue
Prioritize requests sent to services so that requests with a higher priority are received and processed more quickly than those with a lower priority.
Problem: A standard FIFO queue treats all messages equally. High-priority messages (payment confirmations, alerts) wait behind low-priority messages (reports, analytics), degrading the experience for critical operations.
When to use:
- The system serves multiple clients or tenants with different SLAs
- Certain message types must be processed within tighter time bounds
- You need to guarantee that premium or critical workloads are not starved
- Different priorities map to different processing costs or deadlines
WAF Pillars: Reliability, Performance Efficiency
Related patterns: Competing Consumers, Queue-Based Load Leveling, Throttling
31. Publisher/Subscriber
Enable an application to announce events to multiple interested consumers asynchronously, without coupling the senders to the receivers.
Problem: A service that must notify multiple consumers directly becomes tightly coupled to each consumer. Adding a new consumer requires changing the producer. Synchronous calls from the producer to each consumer increase latency and reduce availability.
When to use:
- Multiple consumers need to react to the same event independently
- Producers and consumers should evolve independently
- You need to add new consumers without modifying the producer
- The system benefits from temporal decoupling (consumers process events at their own pace)
WAF Pillars: Reliability, Security, Cost Optimization, Operational Excellence, Performance Efficiency
Related patterns: Choreography, Competing Consumers, Event Sourcing, Queue-Based Load Leveling
32. Quarantine
Ensure external assets meet a team-agreed quality level before being authorized for consumption.
Problem: External artifacts (container images, packages, data files, IaC modules) may contain vulnerabilities, malware, or misconfigurations. Consuming them without validation exposes the system to supply-chain attacks and compliance violations.
When to use:
- You consume third-party container images, packages, or libraries
- Compliance requires scanning artifacts before deployment
- You want to gate promotion of artifacts through quality tiers (untested → tested → approved)
- You need traceability for which version of an external asset is deployed
WAF Pillars: Security, Operational Excellence
Related patterns: Gatekeeper, Gateway Offloading, Pipes and Filters
33. Queue-Based Load Leveling
Use a queue that acts as a buffer between a task and a service it invokes, to smooth intermittent heavy loads.
Problem: Spikes in demand can overwhelm a service, causing throttling, errors, or outages. Over-provisioning to handle peak load wastes resources during normal periods.
When to use:
- The workload is bursty but the backend service scales slowly or is expensive to over-provision
- You need to decouple the rate at which work is submitted from the rate at which it is processed
- You want to flatten traffic spikes without losing requests
- Temporary unavailability of the backend should not result in data loss
WAF Pillars: Reliability, Cost Optimization, Performance Efficiency
Related patterns: Competing Consumers, Priority Queue, Throttling, Bulkhead
34. Rate Limiting
Control the rate of requests a client or service can send to or receive from another service, to prevent overconsumption of resources.
Problem: Without rate limiting, a misbehaving or compromised client can exhaust backend resources, causing service degradation for all consumers. Uncontrolled traffic can also trigger cloud provider throttling or incur excessive costs.
When to use:
- You need to protect shared resources from overconsumption
- You want to enforce fair usage across tenants or clients
- The backend has known capacity limits and you want to stay below them
- You need to prevent cascade failures caused by sudden traffic surges
WAF Pillars: Reliability
Related patterns: Throttling, Bulkhead, Circuit Breaker, Queue-Based Load Leveling
35. Retry
Enable an application to handle anticipated, temporary failures when it tries to connect to a service or network resource, by transparently retrying a failed operation.
Problem: Cloud environments experience transient faults—brief network glitches, service restarts, temporary throttling. If the application treats every failure as permanent, it unnecessarily degrades the user experience or triggers costly failovers.
When to use:
- The failure is likely transient (HTTP 429, 503, timeout)
- Retrying the same request is idempotent or safe
- You want to improve resilience without complex failover infrastructure
- The downstream service is expected to recover within a short window
WAF Pillars: Reliability
Related patterns: Circuit Breaker, Bulkhead, Ambassador, Health Endpoint Monitoring
36. Saga
Manage data consistency across microservices in distributed transaction scenarios.
Problem: Traditional distributed transactions (two-phase commit) are not feasible across microservices with independent databases. Without a coordination mechanism, partial failures leave the system in an inconsistent state.
When to use:
- A business operation spans multiple microservices, each with its own data store
- You need eventual consistency with well-defined compensating actions
- Two-phase commit is not available or would introduce unacceptable coupling
- Each step can be reversed by a compensating transaction
WAF Pillars: Reliability
Related patterns: Compensating Transaction, Choreography, Scheduler Agent Supervisor, Event Sourcing
37. Scheduler Agent Supervisor
Coordinate a set of distributed actions as a single operation. If any of the actions fail, try to handle the failures transparently, or else undo the work that was performed.
Problem: Distributed workflows involve multiple steps across different services. You need a way to track progress, detect failures, retry or compensate, and ensure the workflow reaches a terminal state.
When to use:
- A workflow spans multiple remote services that must be orchestrated
- You need centralized monitoring and control of workflow progress
- Failures should be retried or compensated automatically
- The workflow must guarantee completion or rollback
WAF Pillars: Reliability, Performance Efficiency
Related patterns: Saga, Compensating Transaction, Leader Election, Retry
38. Sequential Convoy
Process a set of related messages in a defined order, without blocking processing of other groups of messages.
Problem: Message ordering is required within a logical group (e.g., all events for a single order), but a strict global order would serialize the entire system and destroy throughput. Different groups are independent and can be processed in parallel.
When to use:
- Messages within a group must be processed in order (e.g., order events, session events)
- Different groups can be processed concurrently
- Out-of-order processing within a group would cause data corruption or incorrect results
- You need high throughput across groups while preserving per-group ordering
WAF Pillars: Reliability
Related patterns: Competing Consumers, Priority Queue, Queue-Based Load Leveling
39. Sharding
Divide a data store into a set of horizontal partitions or shards.
Problem: A single database server has finite storage, compute, and I/O capacity. As data volume and query load grow, vertical scaling becomes prohibitively expensive or hits hardware limits. A single server is also a single point of failure.
When to use:
- A single data store cannot handle the storage or throughput requirements
- You need to distribute data geographically for latency or compliance
- You want to scale horizontally by adding more nodes
- Different subsets of data have different access patterns or SLAs
WAF Pillars: Reliability, Cost Optimization
Related patterns: Index Table, Materialized View, Geode, Deployment Stamps
40. Sidecar
Deploy components of an application into a separate process or container to provide isolation and encapsulation.
Problem: Applications need cross-cutting functionality (logging, monitoring, configuration, networking). Embedding these directly into the application creates tight coupling, language lock-in, and shared failure domains.
When to use:
- The cross-cutting component must run alongside the main application but in isolation
- The main application and the sidecar can be developed in different languages
- You want to extend or add functionality without modifying the main application
- The sidecar has a different lifecycle or scaling requirement than the main application
WAF Pillars: Security, Operational Excellence
Related patterns: Ambassador, Gateway Offloading, Compute Resource Consolidation
41. Static Content Hosting
Deploy static content to a cloud-based storage service that can deliver them directly to the client.
Problem: Serving static files (images, scripts, stylesheets, documents) from the application server wastes compute that should be reserved for dynamic content. It also limits scalability and increases cost.
When to use:
- The application serves static files that do not change per request
- You want to reduce the load on your web servers
- A CDN can accelerate delivery to geographically distributed users
- You want cost-effective, highly available static file hosting
WAF Pillars: Cost Optimization
Related patterns: Valet Key, Geode, Cache-Aside
42. Strangler Fig
Incrementally migrate a legacy system by gradually replacing specific pieces of functionality with new applications and services.
Problem: Rewriting a large legacy system from scratch is risky, expensive, and often fails. The legacy system must continue operating during the migration. A big-bang cutover is not feasible due to risk and business continuity requirements.
When to use:
- You are replacing a monolithic legacy application incrementally
- You need the old and new systems to coexist during migration
- You want to reduce migration risk by delivering value incrementally
- The legacy system is too large or complex for a single-phase replacement
WAF Pillars: Reliability, Cost Optimization, Operational Excellence
Related patterns: Anti-Corruption Layer, Gateway Routing, Sidecar
43. Throttling
Control the consumption of resources used by an instance of an application, an individual tenant, or an entire service.
Problem: Sudden spikes in demand or a misbehaving tenant can exhaust shared resources, degrading the experience for all users. Over-provisioning to handle worst-case load is expensive and wasteful.
When to use:
- You need to enforce SLAs or quotas per tenant in a multi-tenant system
- The backend has known capacity limits and exceeding them causes instability
- You want to degrade gracefully under load rather than fail entirely
- You need to prevent a single workload from monopolizing shared resources
WAF Pillars: Reliability, Security, Cost Optimization, Performance Efficiency
Related patterns: Rate Limiting, Bulkhead, Queue-Based Load Leveling, Priority Queue
44. Valet Key
Use a token or key that provides clients with restricted direct access to a specific resource or service.
Problem: Routing all data transfers through the application server creates a bottleneck and increases cost. Giving clients direct access to the data store without any restriction is a security risk.
When to use:
- You want to minimize the load on the application server for data-intensive transfers (uploads/downloads)
- You need to grant time-limited, scope-limited access to a specific resource
- You want to offload transfer bandwidth to a storage service (Blob Storage, S3)
- Clients need temporary access without full credentials to the data store
WAF Pillars: Security, Cost Optimization, Performance Efficiency
Related patterns: Gatekeeper, Static Content Hosting, Federated Identity