REST & Microservices Interview Questions (50+ Detailed Q&A)
1. REST API Design
1. Six Constraints of REST
1. Six Constraints of REST
- Client-Server: Separation.
- Stateless: Server stores no session.
- Cacheable: Client can cache.
- Uniform Interface: Standard verbs/paths.
- Layered System: LBs/Proxies transparent.
- Code on Demand: (Optional) JS.
2. HTTP Verbs & Idempotency
2. HTTP Verbs & Idempotency
GET: Safe. Idempotent.POST: Create. NOT Idempotent.PUT: Replace/Update. Idempotent.PATCH: Partial Update. NOT Idempotent (technically, depending on op).DELETE: Remove. Idempotent.
3. Status Codes
3. Status Codes
- 2xx: Success (200 OK, 201 Created, 204 No Content).
- 3xx: Redirection (301 Moved Perm, 304 Not Modified).
- 4xx: Client Error (400 Bad Req, 401 Unauth, 403 Forbidden, 404 Not Found, 429 Too Many Reqs).
- 5xx: Server Error (500 Internal, 502 Bad Gateway, 503 Unavailable).
4. REST vs SOAP
4. REST vs SOAP
- SOAP: XML, Strict Contract (WSDL), Transport independent (can use SMTP), Heavy.
- REST: JSON/XML, HTTP based, Lightweight, Flexible.
5. HATEOAS
5. HATEOAS
{ "id": 1, "links": [{ "rel": "delete", "href": "/1" }] }.
Makes API discoverable. Only Root URL needed hardcoded.6. Pagination Strategies
6. Pagination Strategies
- Offset/Limit:
skip=10&limit=10. Slow on deep pages (DB scans skipped rows). - Cursor:
after=cursor_id. Fast. No total count.
7. Versioning Strategies
7. Versioning Strategies
- URI Path:
/v1/users(Most common). - Query Param:
?v=1. - Header:
Accept-Version: v1.
8. Content Negotiation
8. Content Negotiation
Accept: application/json.
Server returns JSON.
If Accept: application/xml, server tries XML. Returns 406 Not Acceptable if unsupported.9. Patch vs Put
9. Patch vs Put
PUT /users/1: Requires sending FULL object. Replaces entire resource.PATCH /users/1: Send only{ "email": "new" }. Merges.
10. Handling Long Running Operations
10. Handling Long Running Operations
202 Accepted immediately.
Include Location: /tasks/123.
Client polls /tasks/123 until status is “Completed”.2. Microservices Architecture
11. Monolith vs Microservices
11. Monolith vs Microservices
- Monolith: Single codebase/deploy. Simple. Scales vertically or cloning. High coupling.
- Microservices: Independent services. Complex ops. Independent scaling/deploy. Loose coupling.
12. Database per Service
12. Database per Service
13. API Gateway pattern
13. API Gateway pattern
14. Service Registry & Discovery
14. Service Registry & Discovery
- Client-side: Client queries Registry (Consul/Eureka).
- Server-side: Client calls LB. LB queries Registry. K8s DNS is Server-side.
15. Sags Pattern (Distributed Transactions)
15. Sags Pattern (Distributed Transactions)
- Choreography: Event based.
- Orchestration: Central coordinator.
16. CQRS (Command Query Responsibility Segregation)
16. CQRS (Command Query Responsibility Segregation)
17. Event Sourcing
17. Event Sourcing
UserCreated, NameChanged).
Replay events to restore state.
Audit trail built-in.18. Circuit Breaker
18. Circuit Breaker
19. Strangler Fig Pattern
19. Strangler Fig Pattern
20. Bulkhead Pattern
20. Bulkhead Pattern
3. Communication Protocols
21. gRPC vs REST
21. gRPC vs REST
- gRPC: HTTP/2. Protobuf (Binary). Bidirectional streaming. Strict schema. Fast (Internal).
- REST: HTTP/1.1. JSON (Text). Request/Response. Flexible. Broad support (External/Browser).
22. GraphQL vs REST
22. GraphQL vs REST
- GraphQL: Client asks for exactly what it needs (No Over-fetching). Single Endpoint. Graph traversal.
- REST: Fixed response structure. Over/Under-fetching. Multiple Endpoints.
23. Webhooks
23. Webhooks
24. Server Sent Events (SSE)
24. Server Sent Events (SSE)
25. WebSockets
25. WebSockets
26. Protocol Buffers (Protobuf)
26. Protocol Buffers (Protobuf)
27. Message Queues (Async)
27. Message Queues (Async)
28. HTTP/2 vs HTTP/1.1
28. HTTP/2 vs HTTP/1.1
- Multiplexing: Single TCP connection for multiple requests. No Head-of-Line blocking.
- Header Compression: HPACK.
- Server Push.
29. HTTP/3 (QUIC)
29. HTTP/3 (QUIC)
30. Idempotency Keys
30. Idempotency Keys
Idempotency-Key: uuid.
Server stores key.
If request retry comes with same key, return cached response instead of processing payment again.4. Security & Scaling
31. OAuth 2.0 flows
31. OAuth 2.0 flows
- Auth Code: Server-side apps. (Standard).
- Client Creds: Machine-to-Machine.
- PKCE: Mobile/SPA (No secret).
32. OpenID Connect (OIDC)
32. OpenID Connect (OIDC)
33. API Rate Limiting
33. API Rate Limiting
X-RateLimit-Remaining.34. Backend for Frontend (BFF)
34. Backend for Frontend (BFF)
35. Service Mesh (Istio/Linkerd)
35. Service Mesh (Istio/Linkerd)
36. API Security Top 10
36. API Security Top 10
37. JWT Vulnerabilities
37. JWT Vulnerabilities
- ‘None’ algorithm attack.
- Secret key Brute-force (Weak secret).
- Replay (Lack of
jti/ exp).
38. CORS details
38. CORS details
Access-Control-Allow-Origin: domain.com.
Access-Control-Allow-Credentials: true (Cookies).39. Horizontal Pod Autoscaling metrics
39. Horizontal Pod Autoscaling metrics
40. Distributed Tracing
40. Distributed Tracing
X-B3-TraceId).
Spans created by each service.
Visualize Request Lifecycle across microservices (Jaeger/Zipkin).5. Operations
41. Log Aggregation
41. Log Aggregation
42. Health Checks (Liveness/Readiness)
42. Health Checks (Liveness/Readiness)
- Liveness: Restart me if dead.
- Readiness: Don’t send traffic until I’m ready (DB connected).
43. Throttling vs Rate Limiting
43. Throttling vs Rate Limiting
- Rate Limit: Policy (User tier).
- Throttling: Protection (Server load high -> Reject everything).
44. Semantic Versioning for APIs
44. Semantic Versioning for APIs
45. API Documentation
45. API Documentation
46. Handling Partial Failures
46. Handling Partial Failures
{ data: ..., errors: [...] } (GraphQL style).47. Sidecar Pattern
47. Sidecar Pattern
48. Twelve-Factor App
48. Twelve-Factor App
49. Canonical Data Model
49. Canonical Data Model
50. Contract Testing
50. Contract Testing