Sep 3, 2026

API

Technical Interview Guide: Welcome to this comprehensive, in-depth preparation guide featuring curated, real-world, and scenario-based Web API and RESTful architecture technical interview questions and answers. Designed specifically for senior backend engineers, API designers, and enterprise software architects, this guide covers architectural constraints, HTTP semantics, idempotency, content negotiation, API gateways, rate limiting, security, caching, and production resilience.

Topics covered: Richardson Maturity Model, Architectural Constraints, Safe vs Idempotent Methods, HTTP/1.1 vs HTTP/2 vs HTTP/3, Status Code Semantics, Versioning Schemes, HATEOAS, RFC 9457 Problem Details, OAuth 2.1 Mutual TLS/DPoP, Token Bucket Rate Limiting, Conditional Requests (ETags, 304 Not Modified), API Gateways, and Webhook Delivery Guarantees.

REST Architectural Constraints & Maturity Model

Answer:
REST (Representational State Transfer) is an architectural style for distributed hypermedia systems. To be considered truly RESTful, a service must adhere to 6 architectural constraints:
  1. Client-Server: Enforces clean separation of concerns. The client manages user interface state, while the server handles data storage and domain logic.
  2. Stateless: Every request from client to server must contain all information required to understand and process the request. No client context is stored on the server between requests.
  3. Cacheable: Responses must explicitly declare themselves as cacheable or non-cacheable to prevent clients from reusing stale data.
  4. Uniform Interface: Simplifies and decouples architecture via 4 sub-constraints: resource identification (URIs), manipulation through representations, self-descriptive messages, and hypermedia (HATEOAS).
  5. Layered System: The client cannot tell whether it is connected directly to the end server or to an intermediary (proxy, cache, API gateway, load balancer).
  6. Code on Demand (Optional): Servers can temporarily extend client functionality by transferring executable code (e.g., JavaScript).
Answer:
The Richardson Maturity Model (RMM) grades an API's adherence to REST principles:
  • Level 0 (The Swamp of POX): Uses HTTP purely as a transport tunnel. A single URI receives all requests (typically via POST) with custom XML/JSON envelopes (e.g., SOAP or basic XML-RPC).
  • Level 1 (Resources): Introduces multiple discrete URIs to represent individual resources (e.g., /orders/123), but still relies on a single HTTP verb (usually POST).
  • Level 2 (HTTP Verbs): Uses standard HTTP verbs (GET, POST, PUT, DELETE, PATCH) according to their intended semantics, and returns appropriate standard HTTP status codes (200, 201, 404, 500). Most commercial "REST" APIs sit at Level 2.
  • Level 3 (Hypermedia Controls / HATEOAS): Responses include hypermedia links that guide the client on what actions and transitions can be performed next based on the current resource state.
Answer:
Statelessness requires that the server never stores session state across requests. Every incoming request must contain authentication credentials, authorization tokens, and all necessary state parameters.

Trade-offs:
  • Advantages: Horizontal scalability is straightforward. Any server node behind a round-robin load balancer can handle any request without session clustering or sticky sessions. Server crash recovery is instantaneous.
  • Disadvantages: Network bandwidth overhead increases because repetitive metadata (e.g., large JWT bearer tokens and headers) must be transmitted in every individual request.
Answer:
* REST: Resource-centric over HTTP. Best for public-facing developer APIs, mobile backends, and standard web integrations leveraging HTTP caching.
* GraphQL: Single endpoint query language. Clients request the exact fields needed, preventing over-fetching/under-fetching. Best for complex, interconnected UIs aggregating data across multiple microservices.
* gRPC: High-performance RPC using HTTP/2 framing and binary Protocol Buffers (Protobuf). Best for low-latency, internal polyglot microservice-to-microservice communication and bi-directional streaming.
* SOAP: Rigid XML protocol with strict WS-* security and transaction standards. Best for enterprise legacy banking, healthcare, and government contracts requiring formal WSDL contracts.
Answer:
The Uniform Interface decouples the client from server implementation details so that both can evolve independently without breaking contracts.

It enforces 4 fundamental requirements:
  1. Identification of Resources: Individual resources are identified by stable, distinct URIs.
  2. Manipulation through Representations: Clients hold an abstract representation (e.g., JSON or XML) of a resource, not the database row directly.
  3. Self-Descriptive Messages: Each message contains enough metadata (e.g., Content-Type: application/json) for the receiver to know how to parse and handle it.
  4. HATEOAS: The client navigates application states purely through links dynamically provided by the server representations.
Answer:
The Layered System constraint dictates that a component cannot see beyond the immediate layer with which it is interacting.

Practical Implementations:
  • Reverse Proxies & Load Balancers (e.g., NGINX, HAProxy): Distribute traffic without the client knowing the backend server IP.
  • Edge Caches & CDNs (e.g., Cloudflare, Akamai): Serve cached representations from edge nodes without hitting origin servers.
  • API Gateways: Handle authentication, TLS termination, and rate-limiting transparently.
Answer:
Code on Demand allows a server to send executable code (e.g., JavaScript scripts, WebAssembly applets) to the client to extend its capabilities at runtime.

It is designated as optional because:
  • It reduces visibility and introduces security vulnerabilities (arbitrary code execution risks on the client).
  • Many non-browser API consumers (e.g., microservices, IoT devices, cron workers) lack execution runtimes to execute dynamic client-side scripts.
Answer:
Common architectural violations include:
  • Tunneling Actions inside GET/POST: Using verbs in URIs like POST /deleteUser?id=5 or GET /updateOrder.
  • Ignoring HTTP Status Codes: Returning 200 OK for all responses while embedding errors in the body: { "status": 500, "error": "Db Fail" }.
  • Stateful Server Sessions: Storing user shopping cart or step-by-step wizard context in server memory (session stickiness).
  • Bypassing Content Negotiation: Hardcoding output formats without respecting Accept and Content-Type headers.
Answer:
* Resource State: The actual data stored persistently on the server (e.g., database records representing an order, account balance, or user profile). It is uniform, shared across all users, and manipulated via HTTP methods.
* Application State: The current progression of a specific client within an interaction flow (e.g., which page of a multi-step checkout wizard the user is currently on).

In REST, Application State must be maintained entirely on the client (or embedded as hypermedia links), never stored in the server's session memory.
Answer:
* HTTP/2: Introduces binary framing and multiplexing over a single persistent TCP connection. Eliminates the need for API bundling tricks (e.g., batch endpoints), supports header compression (HPACK), and removes Head-of-Line (HoL) blocking at the application layer.
* HTTP/3: Replaces TCP with UDP-based QUIC. Completely eliminates transport-level Head-of-Line blocking (packet loss on one stream does not stall adjacent streams) and enables 0-RTT handshakes and seamless network migration between Wi-Fi and mobile cellular data.
Answer:
An API Contract is a machine-readable specification (OpenAPI Specification / OAS) that formally defines endpoints, supported methods, request schemas, authentication requirements, and status code responses.

Governance Benefits:
  • Design-First Development: Enables front-end and back-end teams to agree on schemas and generate mocks before writing implementation code.
  • SDK & Client Generation: Automatically produces strongly-typed client libraries (via OpenAPI Generator).
  • Contract Testing: Validates that server runtime payloads strictly match published schemas, preventing breaking changes.
Answer:
* RPC: Action-Centric. Focuses on executing remote procedures/verbs: /cancelSubscription() or /transferFunds(). URIs describe operations. Often relies on custom payload envelopes.
* REST: Entity/Resource-Centric. Focuses on nouns: /subscriptions/{id} or /transfers. Actions are expressed uniformly through standardized HTTP verbs (POST, PUT, DELETE).
Answer:
Yes. REST is an abstract architectural style, not a protocol standard:
  • While HTTP is the ubiquitous choice, any protocol that provides uniform addressing (URIs), standardized verbs, content negotiation, and metadata headers can implement REST.
  • Examples include CoAP (Constrained Application Protocol) used for RESTful IoT sensor devices over UDP, or custom internal message bus transports that adhere to Fielding's 6 constraints.
Answer:
A Service Mesh (e.g., Istio, Linkerd) uses sidecar proxies (Envoy) to manage inter-service communication:
  • External client traffic enters via an Ingress Gateway running REST over TLS.
  • The mesh transparently intercepts internal calls, applying mutual TLS (mTLS), distributed tracing, rate-limiting, and retries.
  • Internal services often translate external REST calls into lightweight gRPC/binary protocols behind the mesh boundary.
Answer:
* Entity: The concrete business domain model or physical database row (e.g., a record in a SQL Users table with internal hash keys).
* Resource: A conceptual mapping exposed via a URI (e.g., https://api.example.com/users/42).
* Representation: The serialized format (bytes) transmitted over the wire representing the current state of that resource (e.g., a JSON payload, an XML document, or a PDF stream).
© 2026 HelpBox.in :: All Rights Reserved

No comments:

Post a Comment