← Back to Questions
Microservices - Scenario based questions

How will you perform zero-downtime deployment in microservices?

Learn How will you perform zero-downtime deployment in microservices? with simple explanations, real-time examples, interview tips and practical use cases.

How Will You Perform Zero-Downtime Deployment in Microservices?

Zero-downtime deployment means deploying new application versions without affecting users or stopping the system.


Main Goal

Deploy New Version
Without Service Interruption

Why Zero-Downtime Deployment Is Important?

  • 24/7 application availability
  • No customer impact
  • No revenue loss
  • Safe production releases
  • Better user experience
  • Supports continuous delivery

Real Production Example

Suppose:

E-Commerce Application

Services

Order Service
Payment Service
Inventory Service
User Service
Notification Service

Problem

If Payment Service restarts during deployment:

Payments Fail
Orders Fail
Customers Impacted

Goal

Deploy New Payment Version
Without Affecting Users

Production Techniques for Zero-Downtime Deployment

  • Rolling Deployment
  • Blue-Green Deployment
  • Canary Deployment
  • Feature Flags
  • Load Balancer Traffic Switching
  • Kubernetes Readiness & Liveness Probes
  • Backward Compatible APIs
  • Database Migration Strategy
  • Graceful Shutdown
  • Auto Scaling
  • Health Checks
  • Observability & Monitoring

1. Rolling Deployment

Most common deployment strategy in Kubernetes.


Idea

Replace Old Instances Gradually

Example

4 Pods Running

Deployment Flow

Stop Pod 1
Start New Pod 1
      ↓
Stop Pod 2
Start New Pod 2
      ↓
Continue Gradually

Benefits

  • No downtime
  • Gradual replacement
  • Simple implementation

Kubernetes Example

strategy:
  type: RollingUpdate

  rollingUpdate:
    maxUnavailable: 1
    maxSurge: 1

Meaning

Property Meaning
maxUnavailable How many pods can stop
maxSurge Extra pods during deployment

Flow

Old Pod Removed Slowly
New Pod Added Slowly

Problems

  • Rollback slower
  • Mixed versions temporarily running

2. Blue-Green Deployment

Maintain two production environments.


Architecture

Blue Environment → Current Production
Green Environment → New Version

Flow

Deploy New Version To Green
       ↓
Test Green Environment
       ↓
Switch Traffic From Blue To Green

If Problem Occurs

Switch Back To Blue

Benefits

  • Instant rollback
  • Near-zero downtime
  • Safe deployment
  • Easy testing

Problems

  • Double infrastructure cost
  • Database migration complexity

Production Example

Blue → Payment Service v1
Green → Payment Service v2

Traffic Switch

Load Balancer Updated

3. Canary Deployment

Deploy new version to small percentage of users first.


Flow

95% Traffic → Old Version
5% Traffic → New Version

If No Issues

Increase Gradually

Final State

100% Traffic → New Version

If Errors Increase

Rollback Canary

Benefits

  • Reduced risk
  • Early issue detection
  • Safe experimentation

Production Example

New Payment Gateway Logic

Only 5% Users Use It Initially

If successful:

Increase To 20%
Then 50%
Then 100%

4. Feature Flags

Deploy code without enabling feature immediately.


Flow

Deploy New Code
      ↓
Feature Disabled
      ↓
Enable For Small Users
      ↓
Gradually Rollout

Benefits

  • No redeployment needed
  • Fast rollback
  • Controlled rollout

Java Example

if(featureFlagEnabled) {
   useNewPaymentFlow();
}
else {
   useOldPaymentFlow();
}

Popular Tools

  • :contentReference[oaicite:0]{index=0}
  • :contentReference[oaicite:1]{index=1}

5. Load Balancer Traffic Switching

Load balancer routes traffic only to healthy instances.


Architecture

Users
   ↓
Load Balancer
   ↓
Healthy Pods Only

Deployment Flow

New Pod Starts
      ↓
Health Check Passes
      ↓
Load Balancer Sends Traffic

Benefits

  • No requests sent to unhealthy pods
  • Smooth traffic management

Popular Load Balancers

  • :contentReference[oaicite:2]{index=2}
  • :contentReference[oaicite:3]{index=3}
  • :contentReference[oaicite:4]{index=4}

6. Kubernetes Readiness & Liveness Probes

Very important for zero-downtime deployments.


Readiness Probe

Checks whether pod is ready to receive traffic.


Liveness Probe

Checks whether pod is alive.


Kubernetes Example

readinessProbe:
  httpGet:
    path: /health
    port: 8080

Flow

Pod Starts
     ↓
Health Check Runs
     ↓
If Healthy
     ↓
Traffic Allowed

Benefits

  • Prevents traffic to unhealthy pods
  • Safer deployments

7. Graceful Shutdown

Old service instances should not terminate immediately.


Problem

Active Requests Lost

Solution

Finish Existing Requests
Then Shutdown

Spring Boot Example

server.shutdown=graceful

Flow

Stop Receiving New Requests
       ↓
Complete Current Requests
       ↓
Shutdown Safely

Benefits

  • No request loss
  • Better user experience

8. Backward Compatible APIs

During deployment:

Old And New Versions Run Together

Problem

Breaking API changes cause failures.


Best Practice

Never Remove Existing Fields Immediately

Correct Approach

{
  "status":"SUCCESS",
  "paymentStatus":"SUCCESS"
}

Benefits

  • Mixed-version compatibility
  • Safe rolling deployments

9. Database Migration Strategy

Database changes are very risky.


Wrong Approach

Deploy App + DB Breaking Change Together

Correct Approach

Expand And Contract Pattern


Step 1

Add New Columns
Keep Old Columns

Step 2

Deploy New App Version

Step 3

Migrate Data Slowly

Step 4

Remove Old Columns Later

Benefits

  • Zero downtime schema changes
  • Supports mixed versions

10. Auto Scaling During Deployment

Extra capacity helps avoid downtime.


Flow

Increase Pod Count
      ↓
Deploy New Version
      ↓
Reduce Extra Pods Later

Benefits

  • Handles traffic spikes
  • Maintains availability

11. CI/CD Automation

Automated pipelines reduce deployment risks.


Pipeline Flow

Build
  ↓
Unit Tests
  ↓
Integration Tests
  ↓
Security Tests
  ↓
Canary Deployment
  ↓
Monitoring Validation
  ↓
Production Release

Popular CI/CD Tools

  • :contentReference[oaicite:5]{index=5}
  • :contentReference[oaicite:6]{index=6}
  • :contentReference[oaicite:7]{index=7}
  • :contentReference[oaicite:8]{index=8}

12. Observability & Monitoring

Monitor deployment continuously.


Monitor

  • Error rate
  • Latency
  • CPU usage
  • Memory usage
  • HTTP failures
  • Database connections

Monitoring Tools

  • :contentReference[oaicite:9]{index=9}
  • :contentReference[oaicite:10]{index=10}
  • :contentReference[oaicite:11]{index=11}
  • :contentReference[oaicite:12]{index=12}

If Metrics Degrade

Automatic Rollback

13. Service Mesh for Traffic Control

Modern microservices often use service mesh.


Popular Service Mesh Tools

  • :contentReference[oaicite:13]{index=13}
  • :contentReference[oaicite:14]{index=14}

Benefits

  • Traffic splitting
  • Canary deployments
  • Observability
  • Security

Canary Example Using Istio

90% → v1
10% → v2

14. Real Production Example

Scenario

Deploy new Payment Service version.


Production Flow

Deploy Payment v2 Pods
       ↓
Readiness Probes Validate
       ↓
Canary 5% Traffic
       ↓
Monitor Metrics
       ↓
Increase Traffic Gradually
       ↓
100% Production Traffic

If Error Rate Increases

Automatic Rollback

Final Result

  • No downtime
  • No customer impact
  • Safe deployment
  • Fast rollback

Production Best Practices

Practice Purpose
Rolling Deployment Gradual replacement
Blue-Green Deployment Instant rollback
Canary Deployment Reduce deployment risk
Feature Flags Controlled rollout
Readiness Probes Healthy traffic routing
Graceful Shutdown Prevent request loss
Backward Compatibility Mixed-version support
Monitoring Early issue detection

Final Interview Answer

To perform zero-downtime deployment in microservices, I would use deployment strategies such as rolling deployments, blue-green deployments, and canary deployments depending on business requirements. In Kubernetes environments, rolling updates are commonly used to replace old pods gradually while maintaining service availability. For safer releases and instant rollback support, I would use blue-green deployments where traffic is switched between old and new environments. For high-risk changes, I would prefer canary deployments by routing a small percentage of traffic to the new version and gradually increasing traffic after monitoring stability. I would also implement readiness and liveness probes to ensure traffic reaches only healthy instances, graceful shutdown to avoid request loss, and backward-compatible APIs to support mixed-version deployments. Additionally, feature flags help control rollout without redeployment, and monitoring tools like :contentReference[oaicite:15]{index=15} and :contentReference[oaicite:16]{index=16} help detect issues early and trigger rollback if necessary. The overall goal is to deploy new versions safely without impacting users or causing downtime in production systems.

Why this Microservices - Scenario based questions question is important?

This interview question helps candidates understand real-time backend development concepts, practical problem solving, coding fundamentals, system design basics and production-ready application behavior.

Practice this question carefully for Java backend roles, Spring Boot developer interviews, microservices interviews, company interviews and full-stack developer preparation.

About the Author

Naresh Kumar is a Senior Java Backend Engineer with experience building enterprise applications using Java, Spring Boot, Microservices, Docker, Kubernetes and Cloud technologies.