Skip to content

Chapter 4 of 7

Microservices & Service Communication

Monolithic architectures package all application functionality into a single deployable unit, which is simpler to develop and deploy initially but harder to scale individual components and ties the entire system to a single codebase and deployment. Microservices decompose the application into small, independently deployable services that can scale, deploy, and use different technologies independently, with better fault isolation as a key benefit. The trade-off is increased operational complexity in networking, observability, and data consistency.

In a microservices environment, instances come and go dynamically, so services need a way to locate each other. Service discovery provides this mechanism. In client-side discovery, the client queries a service registry such as Netflix Eureka, Consul, etcd, or ZooKeeper, and selects an instance directly. In server-side discovery, the client sends a request to a load balancer or router (such as AWS ALB or Kubernetes kube-proxy), which queries the registry on the client's behalf.

An API gateway acts as a single entry point for all client requests to backend microservices. It handles request routing, authentication and authorization, rate limiting and throttling, request and response transformation, SSL termination, caching, logging, and monitoring. By centralizing these cross-cutting concerns, an API gateway simplifies client interactions. Kong, AWS API Gateway, NGINX, and Apigee are popular implementations.

A reverse proxy similarly sits in front of backend servers and forwards client requests to them, but its focus is on behalf of servers rather than clients, since a forward proxy acts on behalf of clients. Reverse proxies provide security by hiding backend server IPs, perform SSL termination, distribute traffic as a load balancer, serve cached responses, and compress payloads. NGINX, HAProxy, and Traefik are common examples. Underpinning all of this is DNS, the Domain Name System that translates human-readable domain names into IP addresses. Resolution flows from the browser's local cache to a recursive resolver, then through root nameservers, TLD nameservers, and finally authoritative nameservers, with results cached according to their TTL. Common record types include A (IPv4), AAAA (IPv6), CNAME (alias), MX (mail), NS (nameserver), and TXT.

All chapters
  1. 1Scaling Strategies & Load Balancing
  2. 2Caching & Content Delivery
  3. 3Database Design & Distribution
  4. 4Microservices & Service Communication
  5. 5Rate Limiting & Real-Time Communication
  6. 6Messaging, Events & Streaming
  7. 7Distributed Systems: Consistency, Transactions & Resilience

Drill it

Reading is not remembering. These come from the System Design deck:

Q

What is horizontal scaling?

Horizontal scaling (or scaling out) means adding more machines to your resource pool to handle increased load. For example, going from 1 server to 10 servers be...

Q

What is vertical scaling?

Vertical scaling (or scaling up) means adding more power (CPU, RAM, disk) to an existing machine.Advantages:Simpler architecture — no distributed coordination n...

Q

What is a load balancer?

A load balancer distributes incoming network traffic across multiple backend servers to ensure no single server is overwhelmed.It sits between clients and serve...

Q

What are common load balancing algorithms?

Common algorithms:Round Robin — requests are distributed sequentially across serversWeighted Round Robin — servers with higher capacity get more requestsLeast C...