API / Microservices Design Patterns Interview Questions
1. What is the Decompose by Business Capability pattern and how do you identify business capabilities?
The Decompose by Business Capability pattern assigns one microservice per business capability — a stable, high-level function the organisation performs to deliver value. A business capability answers "what does this part of the business do?"...
2. What is the Decompose by Subdomain pattern and how does it relate to DDD Bounded Contexts?
The Decompose by Subdomain pattern uses Eric Evans' Domain-Driven Design taxonomy to carve out service boundaries. A subdomain is a coherent slice of the problem domain....
3. What is the Strangler Fig pattern and when should you use it to migrate a monolith?
The Strangler Fig pattern — coined by Martin Fowler after the strangler fig tree that gradually wraps and replaces its host — is an incremental migration strategy for moving functionality out of a monolith into microservices. Instead of a risky...
4. What is the Anti-Corruption Layer (ACL) pattern in microservices?
The Anti-Corruption Layer (ACL) is a translation boundary placed at the edge of a service to prevent an external model — typically from a legacy system or a foreign bounded context — from contaminating the service's own domain model. Without...
5. What is the Branch by Abstraction pattern for incremental migration?
Branch by Abstraction is an incremental migration technique that replaces an existing component without disrupting the codebase or requiring a long-lived code branch. The key mechanic is introducing an abstraction (an interface or abstract class) over the existing component so...
6. What is the Parallel Run pattern and how does it reduce migration risk?
The Parallel Run pattern runs an old and a new implementation simultaneously against the same live production input, comparing their outputs to verify correctness before committing to the new system. The legacy system's response is always returned to the caller...
7. What is the Bulkhead decomposition pattern and how does it isolate failure domains?
The Bulkhead pattern — named after the watertight compartments in a ship's hull that prevent a single breach from flooding the entire vessel — partitions a system into isolated failure domains so that a critical failure in one domain cannot...
8. What is the Database per Service pattern and what problem does it solve?
The Database per Service pattern mandates that each microservice owns its own persistent data store exclusively. No other service may directly read or write to that store — access is only possible through the owning service's published API....
9. What is the Shared Database anti-pattern and why should it be avoided in microservices?
The Shared Database anti-pattern occurs when two or more microservices bypass each other's APIs to directly read from and write to the same database schema. It is the most common mistake teams make when splitting a monolith, because it initially...
10. What is the Saga pattern and how does it manage distributed transactions across microservices?
The Saga pattern manages a long-running business transaction that spans multiple services without using a distributed two-phase commit (2PC). A Saga is a sequence of local transactions: each step performs a local commit and then publishes an event or sends...
11. What is the difference between Choreography-based and Orchestration-based Sagas?
Both styles implement the Saga pattern (Q10) but differ fundamentally in how the steps are coordinated. In Choreography , there is no central authority: each service listens for domain events published by the preceding step and reacts autonomously, emitting its...
12. What is CQRS (Command Query Responsibility Segregation) and when should you use it?
CQRS separates a service's data model into two distinct paths: a Command side that handles writes (state changes) and a Query side that handles reads. Each side can use a different data store, different data model, and even a different...
13. What is Event Sourcing and how does it complement CQRS?
Event Sourcing stores the state of a domain entity not as its current snapshot in a row, but as an append-only log of every domain event that has ever happened to it. The current state is derived on demand by...
14. What is the API Composition pattern for querying data across services?
The API Composition pattern implements a query that requires data from multiple microservices by having an API composer — typically the API gateway, a BFF, or a dedicated aggregation service — call each relevant service in parallel, then join and...
15. What is the Outbox Pattern and how does it solve the dual-write problem?
The dual-write problem arises when a service must atomically write to its own database and publish a message to a message broker in a single operation. If it writes to the DB but crashes before publishing, other services never learn...
16. What is the Saga rollback / compensating transaction pattern?
In a Saga (Q10), when a step fails, previously completed steps cannot be undone with a database ROLLBACK because each step has already committed its local transaction and those locks are released. Instead, the Saga executes compensating transactions — purpose-built...
17. What is the API Gateway pattern and what responsibilities should it have versus a BFF?
The API Gateway is a single entry point that sits between external clients and the internal microservice topology. Rather than exposing each service's API directly to the internet, all traffic flows through the gateway....
18. What is the Backend for Frontend (BFF) pattern and when does it replace a general API Gateway?
The Backend for Frontend (BFF) pattern creates a dedicated API backend for each distinct client type — one BFF for the mobile app, one for the web SPA, one for third-party integrations. Each BFF is owned by the team building...
19. What is the Service Mesh pattern and how do data-plane proxies such as Envoy implement it?
A Service Mesh is an infrastructure layer that handles all service-to-service communication concerns — traffic management, mutual TLS, retries, circuit breaking, observability — without requiring application code to implement any of it. It consists of two planes: Data plane —...
20. What is the Message Broker pattern and how does it enable asynchronous microservice communication?
The Message Broker pattern introduces a durable intermediary — the broker (Apache Kafka, RabbitMQ, AWS SQS/SNS) — between a producer service and one or more consumer services. The producer publishes a message to the broker and returns immediately without waiting...
21. What is the Request-Reply (Correlation ID) pattern for async messaging?
The Request-Reply pattern enables synchronous-like request/response semantics over an asynchronous message channel. The requestor sends a message to a request channel, attaches a unique Correlation ID and a reply-to address (a dedicated reply channel or a temporary queue), and waits...
22. What is the Idempotent Consumer pattern and why is it essential in event-driven systems?
The Idempotent Consumer pattern ensures that processing the same message more than once produces the same outcome as processing it exactly once. It is essential because virtually all message brokers (Kafka, RabbitMQ, SQS) guarantee at-least-once delivery — a message may...
23. What is the Event-Driven Architecture pattern and how does it differ from synchronous request/response?
Event-Driven Architecture (EDA) structures communication around events — immutable records of something that has happened. A producer emits an event to a broker and moves on without knowing or caring who consumes it....
24. What is Gateway Aggregation versus Gateway Routing versus Gateway Offloading?
These three responsibilities are often all assigned to an API Gateway, but they serve distinct purposes and are worth understanding separately. Responsibility What it does Example Gateway Routing Forwards an inbound request to a single downstream service based on URL...
25. How does the Circuit Breaker pattern work and what are its three states?
The Circuit Breaker pattern prevents cascading failures by detecting when a downstream service is unavailable and fast-failing subsequent calls instead of letting them queue up and exhaust threads. It is named after the electrical circuit breaker that trips when current...
26. What is the Retry pattern with exponential backoff and jitter, and when should you NOT retry?
The Retry pattern automatically re-attempts a failed operation a limited number of times before declaring it a final failure. On its own, retrying immediately (fixed delay or no delay) can overwhelm a struggling downstream service....
27. What is the Timeout pattern and how does it prevent cascading failures?
The Timeout pattern sets an upper bound on how long a caller will wait for a response from a downstream service. Without timeouts, a slow or unresponsive service causes the calling service's request-handling threads to block indefinitely....
28. What is the Bulkhead pattern for resource isolation (thread pools, connection pools)?
The Bulkhead pattern at the resource level isolates the thread pools and connection pools used to call different downstream dependencies, so that a slow or failed dependency cannot monopolise the shared pool and block calls to unrelated services. Without Bulkhead:...
29. What is the Health Check API pattern and what should a /health endpoint return?
The Health Check API pattern exposes an HTTP endpoint (typically /health , /actuator/health , or /healthz ) that returns the current operational status of a service instance. Load balancers, orchestrators (Kubernetes), and service registries poll this endpoint to determine whether...
30. What is the Rate Limiting pattern and what algorithms are commonly used?
The Rate Limiting pattern caps the number of requests a client (identified by IP, API key, or user ID) can make within a time window. When the limit is exceeded, the server rejects excess requests with an HTTP 429 (Too...
31. What is the Fallback pattern and how does it relate to the Circuit Breaker?
The Fallback pattern provides an alternative response path when a downstream call fails — whether due to a timeout, an exception, or a Circuit Breaker (Q25) in the Open state. Instead of propagating a hard error to the caller (and...
32. What is the Throttling pattern and how does it differ from Rate Limiting?
Both Throttling and Rate Limiting control the flow of requests to protect a service from overload, but they differ in what they do to excess traffic. Aspect Rate Limiting Throttling What happens to excess requests Rejected immediately — HTTP 429...
33. What is the Log Aggregation pattern and how does a centralised logging pipeline work?
The Log Aggregation pattern collects log output from every service instance and ships it to a centralised store where it can be searched, correlated, and analysed in one place. Without aggregation, diagnosing an incident across 50 service instances means SSHing...
34. What is the Application Metrics pattern and what is the difference between push and pull metric collection?
The Application Metrics pattern instruments each service to emit numeric measurements — counters, gauges, histograms, and summaries — that describe its runtime behaviour. These metrics feed dashboards, alerting rules, and capacity-planning models that plain logs cannot efficiently support (logs a
35. What is the Audit Logging pattern and what events should always be captured?
Audit Logging records a tamper-evident, chronological trail of who performed what action on which resource and when . It is distinct from application or debug logging: application logs record technical events (exceptions, slow queries, service calls) for operational troubleshooting; audit...
36. What is the Distributed Tracing pattern and how do trace context headers propagate across services?
Distributed Tracing reconstructs the end-to-end path of a single request as it flows across multiple microservices, providing a flamegraph of timings that reveals where latency accumulates and where failures occur. Without it, correlating logs from 10 services for a single...
37. What is the Access Token pattern (JWT/OAuth2) for service-to-client authentication?
The Access Token pattern uses short-lived cryptographically signed tokens — most commonly JWTs issued via OAuth 2.0 / OpenID Connect — to authenticate client requests to microservices. The client authenticates once with an Authorization Server (Keycloak, Okta, Cognito) and receives...
38. What is the Mutual TLS (mTLS) pattern for service-to-service authentication?
Mutual TLS (mTLS) extends standard one-way TLS by requiring both sides of a connection to present and verify X.509 certificates. In a microservices context it provides two things simultaneously: an encrypted channel (confidentiality and integrity) and verified service identity (authentication)...
39. What is the Secrets Management pattern and how do tools like Vault or AWS Secrets Manager implement it?
The Secrets Management pattern centralises the storage, access control, rotation, and auditing of sensitive credentials — database passwords, API keys, TLS certificates, encryption keys — in a dedicated secrets store rather than hardcoding them in environment variables, config files, or...
40. What is the Sidecar pattern and what responsibilities does a sidecar container take on?
The Sidecar pattern deploys a helper container alongside the main application container in the same pod (Kubernetes) or VM instance. The sidecar shares the same network namespace, localhost address space, and optionally a shared volume with the main container....
41. What is the Ambassador pattern and how does it proxy outbound traffic for a service?
The Ambassador pattern is a specialisation of the Sidecar pattern focused on outbound (egress) connections. The ambassador container acts as a local proxy for all traffic the main container sends to external services....
42. What is the Adapter pattern in the context of microservice containers?
The Adapter pattern (container / structural variant) places a sidecar container alongside the main container to normalise the main container's output into a standard interface that the surrounding infrastructure expects — without modifying the main application. It is essentially a...
43. What is the Canary Deployment pattern and how does it differ from Blue-Green deployment?
The Canary Deployment pattern releases a new version of a service to a small percentage of production traffic first, monitors it closely for errors, latency regressions, and business metric anomalies, then gradually increases its traffic share until it serves 100%...
44. What is the Service Registry and Discovery pattern — client-side versus server-side discovery?
The Service Registry is a database of network locations (host + port) for all running service instances, kept up-to-date by registration (at startup) and deregistration (at shutdown or failure). Service Discovery is the mechanism by which a service caller looks...
45. What is the Self Registration versus Third-Party Registration pattern for service discovery?
These two patterns describe how service instances get their network location recorded in (and removed from) the Service Registry — not how callers use it. Self Registration — the service instance itself registers with the registry on startup and deregisters...