← Back to Questions
Microservices - Scenario based questions

One service is deployed with incompatible API changes and other services start failing. How will you prevent this?

Learn One service is deployed with incompatible API changes and other services start failing. How will you prevent this? with simple explanations, real-time examples, interview tips and practical use cases.

One Service Is Deployed With Incompatible API Changes and Other Services Start Failing — How Will You Prevent This?

This is one of the most common and dangerous problems in microservices architecture.


Problem Scenario

Suppose:

Order Service calls Payment Service

Old API Response

{
   "status":"SUCCESS",
   "transactionId":"TXN123"
}

Payment Team Deploys New Version

{
   "paymentStatus":"SUCCESS",
   "txnId":"TXN123"
}

Problem

Order Service still expects:

status
transactionId

Result

JSON Parsing Failure
NullPointerException
Order Processing Failure
Production Outage

This Problem Is Called

Backward Compatibility Failure


Main Goal

New Changes Should Not Break Existing Consumers

Production Techniques to Prevent Incompatible API Failures

  • Backward Compatible APIs
  • API Versioning
  • Consumer-Driven Contract Testing
  • Schema Validation
  • API Gateway Governance
  • Feature Flags
  • Canary Deployment
  • Blue-Green Deployment
  • Semantic Versioning
  • Centralized API Documentation
  • Event Schema Evolution
  • Observability and Monitoring

1. Design Backward Compatible APIs

This is the MOST IMPORTANT rule.


Golden Rule

Never Remove Existing Fields Suddenly

Wrong Change

Old Field:
status

New Field:
paymentStatus

Why Wrong?

Existing consumers break immediately.


Correct Approach

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

Benefits

  • Old clients continue working
  • New clients can migrate gradually

Another Rule

Add New Fields
Do Not Remove Old Fields Immediately

Safe API Evolution

Safe Changes Unsafe Changes
Add optional fields Remove existing fields
Add new endpoints Rename existing fields
Add optional headers Change response structure
Add new enums carefully Change data type

2. API Versioning

Never break old APIs directly.


Use Versioned APIs

/api/v1/payment
/api/v2/payment

Benefits

  • Old consumers continue using v1
  • New consumers migrate to v2
  • Controlled migration

Spring Boot Example

@RestController
@RequestMapping("/api/v1/payments")
public class PaymentControllerV1 {

}

New Version

@RestController
@RequestMapping("/api/v2/payments")
public class PaymentControllerV2 {

}

Best Practice

Deprecate old APIs slowly instead of immediate removal.


Production Flow

Release v2
      ↓
Notify Consumers
      ↓
Monitor Usage
      ↓
Gradually Remove v1

3. Consumer-Driven Contract Testing

One of the most important production techniques.


Problem

Provider team changes API without knowing consumer expectations.


Solution

Consumer-Driven Contracts (CDC)


How It Works

Consumer Defines Expected Contract
      ↓
Provider Must Pass Contract Tests

Popular Tool

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

Flow

Order Service Creates Contract
      ↓
Payment Service CI Pipeline Verifies
      ↓
Deployment Allowed Only If Compatible

Benefits

  • Detect breaking changes early
  • Prevent production outages
  • Safe deployments

Example Contract

{
   "status":"SUCCESS",
   "transactionId":"TXN123"
}

If Provider Removes "status"

Contract Test Fails
Deployment Blocked

4. Schema Validation

Use strict API schemas.


Popular Standards

  • OpenAPI
  • Swagger
  • JSON Schema
  • Avro Schema
  • Protobuf

Benefits

  • Clear API contracts
  • Validation support
  • Compatibility checks

OpenAPI Example

status:
   type: string
transactionId:
   type: string

5. Event Schema Evolution

Kafka event changes can also break systems.


Old Event

{
   "orderId":"ORD1",
   "amount":100
}

Wrong Change

{
   "id":"ORD1",
   "price":100
}

Consumers Break

Because field names changed.


Correct Evolution

{
   "orderId":"ORD1",
   "amount":100,
   "price":100
}

Use Schema Registry

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

Benefits

  • Backward compatibility checks
  • Producer-consumer safety
  • Version management

6. API Gateway Governance

API Gateway acts as centralized control layer.


Responsibilities

  • Routing
  • Authentication
  • Rate limiting
  • Version management
  • Traffic control

Popular Gateways

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

Benefits

  • Centralized API governance
  • Safe routing between versions
  • Traffic management

7. Feature Flags

Deploy code without exposing to everyone immediately.


Flow

Deploy New Feature
      ↓
Enable For Small Users
      ↓
Monitor
      ↓
Gradually Increase

Benefits

  • Reduced deployment risk
  • Fast rollback
  • Controlled rollout

Popular Tools

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

8. Canary Deployment

Deploy new version to small percentage of traffic first.


Flow

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

If Errors Increase

Rollback Immediately

Benefits

  • Reduced blast radius
  • Early detection
  • Safer production deployments

9. Blue-Green Deployment

Maintain two production environments.


Architecture

Blue Environment → Current Production
Green Environment → New Version

Flow

Deploy To Green
      ↓
Test
      ↓
Switch Traffic

If Problem Occurs

Switch Back To Blue

Benefits

  • Instant rollback
  • Near-zero downtime
  • Safer releases

10. Semantic Versioning

Use proper versioning standards.


Format

MAJOR.MINOR.PATCH

Example

2.1.5

Meaning

Version Part Meaning
MAJOR Breaking changes
MINOR Backward-compatible features
PATCH Bug fixes

Benefits

  • Clear compatibility expectations
  • Safer upgrades

11. CI/CD Pipeline Validation

Deployment pipelines should validate compatibility.


Pipeline Steps

Build
  ↓
Unit Tests
  ↓
Contract Tests
  ↓
Integration Tests
  ↓
Compatibility Validation
  ↓
Deploy

Benefits

  • Prevent broken deployments
  • Automated quality checks

12. Observability and Monitoring

Detect failures immediately after deployment.


Monitor

  • Error rates
  • API failures
  • Latency
  • Consumer errors
  • Schema validation failures

Tools

  • :contentReference[oaicite:7]{index=7}
  • :contentReference[oaicite:8]{index=8}
  • :contentReference[oaicite:9]{index=9}
  • :contentReference[oaicite:10]{index=10}

13. Backward Compatible Database Changes

Database schema changes can also break services.


Wrong Migration

Drop Existing Column

Correct Migration

Add New Column
Keep Old Column Temporarily
Migrate Data Slowly
Remove Later

14. Production Incident Example

Problem

Payment Service renamed:

transactionId → txnId

Impact

  • Order Service parsing failed
  • Payments succeeded
  • Orders marked failed
  • Revenue reconciliation issues

Root Cause

  • No contract testing
  • No versioning
  • Breaking change directly deployed

Fix Applied

  • Restored old fields
  • Introduced API v2
  • Added Pact contract testing
  • Implemented canary deployment
  • Added schema validation

Final Result

Safe API Evolution
No Consumer Breakage
Controlled Migration

Production Best Practices

Practice Purpose
Backward Compatibility Prevent consumer failures
API Versioning Safe evolution
Contract Testing Detect breaking changes
Canary Deployment Reduce deployment risk
Feature Flags Controlled rollout
Schema Registry Event compatibility
Monitoring Early issue detection
Blue-Green Deployment Fast rollback

Final Interview Answer

To prevent failures caused by incompatible API changes in microservices, I would follow strict backward compatibility principles and safe API evolution strategies. I would avoid removing or renaming existing fields directly and instead introduce new fields gradually while maintaining support for old consumers. I would implement API versioning using endpoints like /v1 and /v2 to support controlled migration. Additionally, I would use consumer-driven contract testing with tools like :contentReference[oaicite:11]{index=11} to ensure provider changes do not break consumers. For event-driven systems, I would use schema validation and schema registries to manage Kafka event compatibility safely. I would also use canary deployments, blue-green deployments, feature flags, CI/CD compatibility checks, API gateways, and observability tools like :contentReference[oaicite:12]{index=12} and :contentReference[oaicite:13]{index=13} to detect issues early and support fast rollback. The overall goal is to ensure safe deployments, backward compatibility, and zero downtime during API evolution in production microservices 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.