Design Patterns Used at Different Software Layers

Client Layer

PatternDescription
Client Side Load BalancingDistributes requests from the client directly to the available service instances.
State PatternAllows an object to alter its behaviour when its internal state changes.
Composite UI PatternComposes responses from multiple microservices to render the complete UI.

Load Balancer Layer

PatternDescription
Geographical DistributionRoutes traffic based on the geographical location of the client.
Health ChecksPeriodically checks the health of the servers and routes traffic only to healthy ones.
Affinity Based RoutingRoutes the user's request to the same server for maintaining session persistence.
Least ConnectionsRoutes traffic to the server with the fewest active connections.

API Gateway Layer

PatternDescription
Backend for Frontend (BFF)Tailors API responses to the needs of individual client types.
Circuit BreakerDetects failures and prevents applications from trying to perform actions that are doomed to fail.
Retry Pattern:Helps to handle transient failures when it tries to connect to a remote service or network resource.
Request CollapsingCollapses multiple requests for the same operation into a single request

Web Server Layer

PatternDescription
Page Cache PatternStores the output of expensive operations and reuse it to avoid duplicated work.
Compression PatternReduces the size of the response to improve load times.
Lazy LoadingDefers initialization of an object until the point at which it is needed.
Content Negotiation PatternThe server generates different versions of a resource and serves the one matching the client’s criteria.

Appplication Server Layer

PatternDescription
Saga PatternManages long-running transactions and deals with failures and compensating transactions.
CQRS (Command Query Responsibility Segregation)Separates read and write operations to improve performance and scalability.
Proxy PatternProvides a surrogate or placeholder for another object to control access to it.
Chain of ResponsibilityPasses the request along a chain of handlers.

Caching Layer

PatternDescription
Sidecar CachingDeploy a dedicated cache alongside each microservice to provide isolated and scalable caching functionality.
Cache ChainingArrange multiple cache layers hierarchically to handle different granularity or lifetime, querying each layer sequentially on a cache miss.
Time-to-Live (TTL) CachingAssigns a predefined lifespan to each cache entry, removing or refreshing the entry once its lifespan expires.

Content Delivery Network Layer

PatternDescription
PrefetchingAnticipates user actions and loads resources ahead of time.
Parallel RequestingMakes multiple requests in parallel to improve load times.
Edge ComputingProcesses data closer to the location where it is needed.
Domain ShardingSplits resources across multiple domains to increase parallel downloads.
Adaptive ImageDelivery: Delivers images tailored to the device and user context.

Database Layer

PatternDescription
Sharding PatternDistributes data across multiple databases to improve scalability.
Replication PatternKeeps copies of data in multiple locations for availability and reliability.
Read-Replica PatternUses read replicas to offload read operations from the primary database instance.
Query Object PatternAn object that represents a database query.