REVIEWED STARTER COLLECTION

Backend Interview Questions

Ye collection Spring Boot aur SQL ke canonical interview chapters ko repeat nahi karta. Focus framework-neutral backend reasoning aur API/application boundaries par hai.

1. What makes a good HTTP API contract?

Short Answer

A good API contract clearly defines resources, routes, HTTP methods, request/response shapes, status codes and error behavior so clients know what to send and what to expect.

Detailed Explanation

The contract should be predictable and stable enough for clients to integrate safely. Method choice should match the intended operation, validation errors should be consistent, and successful and failed responses should use meaningful HTTP status codes instead of always returning the same status.

GET  /courses/42       -> read a course
POST /courses          -> create a course
PATCH /courses/42      -> update selected fields
DELETE /courses/42     -> request deletion
Review HTTP methods →Review status codes →

2. What does idempotency mean in a backend API?

Short Answer

An operation is idempotent when repeating the same request has the same intended effect on server state as performing it once.

Detailed Explanation

Idempotency matters when clients retry after timeouts or network failures. Read operations are naturally expected not to create repeated side effects, while write operations may need careful design or an idempotency key when duplicate execution would be harmful.

PUT /users/42/preferences

{
  "theme": "dark"
}
Review idempotency →

3. What is the difference between authentication and authorization?

Short Answer

Authentication establishes who the caller is. Authorization decides what that authenticated caller is allowed to do.

Detailed Explanation

A backend might authenticate a user from a session or token, then evaluate ownership, roles or permissions before allowing access to a resource. Being logged in does not automatically grant permission to every operation.

if (!user) return 401;          // not authenticated
if (!canEdit(user, course)) {
  return 403;                   // authenticated, not allowed
}
Review API authentication basics →

4. Why do multi-step backend operations often need a database transaction?

Short Answer

A transaction lets related database changes succeed or fail as one consistency unit, reducing the chance of leaving partial state behind.

Detailed Explanation

Suppose an enrollment operation creates an enrollment row and updates seat availability. If the second step fails after the first succeeds, the data may become inconsistent. A transaction lets the backend commit the whole unit when it succeeds or roll it back when required.

BEGIN;
INSERT INTO enrollments (...);
UPDATE courses
SET seats_left = seats_left - 1
WHERE id = 42;
COMMIT;
Review database transactions →

5. Why should backend APIs paginate large result sets?

Short Answer

Pagination limits how much data is read, processed, transferred and rendered in one request instead of returning an unbounded collection.

Detailed Explanation

Large responses increase database work, memory usage, latency and network cost. A backend should define sensible limits and deterministic ordering. Offset/page pagination can be simple, while cursor-based approaches can be useful for large or frequently changing datasets.

GET /courses?limit=20&cursor=next-token

{
  "items": [...],
  "nextCursor": "..."
}
Review pagination →