liveBook · Manning

Replica

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

A replica is an additional running instance that duplicates the functionality of another service or component.

A replica is an additional running instance of a microservice or component. Multiple replicas provide redundancy: a load balancer distributes requests across instances, while Kubernetes restarts failed instances. section 11.1 section 11.4.4

Use replicas to:

  • Maintain service during intermittent failures by redirecting requests to surviving instances. section 11.4.4
  • Distribute a larger workload across multiple instances when a microservice becomes a performance bottleneck. section 12.3.3
  • Recover failed instances with Kubernetes while continuing to log and investigate failures. section 11.4.4

Set three gateway replicas

Update a Kubernetes Deployment so its replicas field is 3, then apply the YAML with kubectl apply. The gateway runs three redundant instances instead of one. section 11.4.4

Listing 11.2 Adding replicas to our gateway microservice
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gateway
spec:
  replicas: 3     #1
  selector:
    matchLabels:
      app: gateway
  template:
    metadata:
      labels:
        app: gateway
    spec:
      --snip--

Inspect the Deployment YAML showing where the replica count is configured. section 11.4.4

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Explains load balancing, restart behavior, and Kubernetes configuration, while deferring performance scaling details to a separate treatment.
Examples
Demonstrates three gateway instances behind a load balancer and another instance handling messages after a crash.
What it assumes
Assumes a deployed microservice and an existing Kubernetes Deployment YAML configuration.
What you can do after
Operate replicas by changing a Kubernetes Deployment field and applying the configuration with kubectl.
How it connects
Connects replicas with microservices, Kubernetes, deployments, load balancers, redundancy, fault tolerance, horizontal scaling, and message queues.

Also explained in

Compare how 12 books explain replica →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.