Skip to main content
Separating out the web layer from the application layer (also known as platform layer) allows you to scale and configure both layers independently. Adding a new API results in adding application servers without necessarily adding additional web servers. The single responsibility principle advocates for small and autonomous services that work together. Small teams with small services can plan more aggressively for rapid growth. Application Layer Workers in the application layer also help enable asynchronism.

Microservices

Related to this discussion are microservices, which can be described as a suite of independently deployable, small, modular services. Each service runs a unique process and communicates through a well-defined, lightweight mechanism to serve a business goal.

Example Architecture

Pinterest, for example, could have the following microservices:
  • User profile
  • Follower
  • Feed
  • Search
  • Photo upload
  • Etc.

Microservices Benefits

  • Independent deployment - Each service can be deployed independently
  • Independent scaling - Scale individual services based on their specific needs
  • Technology flexibility - Different services can use different technologies
  • Team autonomy - Small teams can own and manage individual services
  • Fault isolation - Failure in one service doesn’t bring down the entire system

Service Discovery

Systems such as Consul, Etcd, and Zookeeper can help services find each other by keeping track of registered names, addresses, and ports.

How Service Discovery Works

  1. Services register themselves with the service discovery system
  2. Services query the discovery system to find other services
  3. Health checks verify service integrity
  4. Failed services are automatically removed from the registry

Health Checks

Health checks help verify service integrity and are often done using an HTTP endpoint. Both Consul and Etcd have a built in key-value store that can be useful for storing config values and other shared data.
  • Adding an application layer with loosely coupled services requires a different approach from an architectural, operations, and process viewpoint (vs a monolithic system).
  • Microservices can add complexity in terms of deployments and operations.
Microservices Trade-off: While microservices provide flexibility and scalability, they introduce operational complexity. Consider starting with a monolith and evolving to microservices as needed.

Source(s) and Further Reading

Build docs developers (and LLMs) love