Backend Questions Practice Sheet - Revise Your Backend Syntax Skills

2026-01-29

Backend Questions Practice Sheet - Revise Your Backend Syntax Skills

Join Our Community for Updates

Stay up-to-date with the latest news, discussions, and updates! Join our WhatsApp group to connect with the community.

Join our WhatsApp Group

Follow me on Instagram

Follow me on X


🚀 Level Up Your Backend Skills

Buy NodeJS Backend Cohort @ ₹699 on https://learn.aakashdev.in/

Master backend development with hands-on projects, real-world scenarios, and expert guidance. Join the cohort to build production-ready backend applications!


Practice Questions

Use these questions to revise and strengthen your backend syntax skills. Each question includes the expected output to help you verify your solutions.


Easy Level Questions

Question 1: Create a Simple Express Server

Task: Create an Express server that listens on port 3000 and responds with "Hello, Backend!" when accessing the root route.

Expected Output:

Server running on http://localhost:3000
When accessing http://localhost:3000, response: "Hello, Backend!"

Question 2: Basic GET Endpoint

Task: Create a GET endpoint /api/users that returns a JSON array of users with id, name, and email fields.

Expected Output:

[
  { "id": 1, "name": "John Doe", "email": "john@example.com" },
  { "id": 2, "name": "Jane Smith", "email": "jane@example.com" }
]

Question 3: POST Endpoint with Body Parsing

Task: Create a POST endpoint /api/users that accepts JSON data with name and email, and returns the created user with an id.

Expected Output:

Request: POST /api/users
Body: { "name": "Alice", "email": "alice@example.com" }
Response: { "id": 1, "name": "Alice", "email": "alice@example.com" }

Question 4: Route Parameters

Task: Create a GET endpoint /api/users/:id that returns a user by ID. If user not found, return 404.

Expected Output:

GET /api/users/1 → { "id": 1, "name": "John Doe", "email": "john@example.com" }
GET /api/users/999 → Status: 404, { "error": "User not found" }

Question 5: Query Parameters

Task: Create a GET endpoint /api/search that accepts query parameters q and limit, and returns filtered results.

Expected Output:

GET /api/search?q=john&limit=5
Response: Array of results matching "john" with max 5 items

Question 6: Middleware for Logging

Task: Create a middleware that logs the HTTP method and URL of every request.

Expected Output:

GET /api/users → Console: "GET /api/users"
POST /api/users → Console: "POST /api/users"

Question 7: Error Handling Middleware

Task: Create an error handling middleware that catches errors and returns a JSON error response.

Expected Output:

Error occurs → Response: { "error": "Internal Server Error", "status": 500 }

Question 8: Basic Authentication Check

Task: Create a middleware that checks for an Authorization header. If missing, return 401.

Expected Output:

Request without Authorization header → Status: 401, { "error": "Unauthorized" }
Request with Authorization header → Proceeds to next middleware

Question 9: CORS Configuration

Task: Configure CORS to allow requests from http://localhost:3000.

Expected Output:

Request from http://localhost:3000 → Allowed
Request from other origin → Blocked (if not configured)

Question 10: Environment Variables

Task: Create a server that reads the port number from an environment variable PORT, defaulting to 3000.

Expected Output:

PORT=8080 → Server runs on port 8080
No PORT set → Server runs on port 3000

Medium Level Questions

Question 11: RESTful CRUD Operations

Task: Implement full CRUD operations for a /api/products endpoint (GET all, GET by ID, POST, PUT, DELETE).

Expected Output:

GET /api/products → Array of all products
GET /api/products/1 → Single product object
POST /api/products → Creates and returns new product
PUT /api/products/1 → Updates and returns updated product
DELETE /api/products/1 → Deletes product, returns success message

Question 12: Request Validation

Task: Create a POST endpoint /api/register that validates email (must be valid email) and password (min 8 characters). Return validation errors if invalid.

Expected Output:

Valid data → { "message": "User registered successfully", "user": {...} }
Invalid email → { "error": "Invalid email format" }
Short password → { "error": "Password must be at least 8 characters" }

Question 13: Async/Await with Database

Task: Create a GET endpoint that fetches users from a database using async/await. Handle database connection errors.

Expected Output:

Success → Returns array of users from database
Database error → Returns 500 with error message

Question 14: File Upload Endpoint

Task: Create a POST endpoint /api/upload that accepts a file upload and saves it to a uploads directory.

Expected Output:

File uploaded → { "message": "File uploaded successfully", "filename": "example.jpg" }
No file → { "error": "No file provided" }

Question 15: Pagination

Task: Create a GET endpoint /api/posts that accepts page and limit query parameters and returns paginated results.

Expected Output:

GET /api/posts?page=1&limit=10
Response: {
  "data": [...],
  "pagination": {
    "page": 1,
    "limit": 10,
    "total": 100,
    "totalPages": 10
  }
}

Question 16: JWT Token Generation

Task: Create a POST endpoint /api/login that generates a JWT token for authenticated users.

Expected Output:

Valid credentials → { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "user": {...} }
Invalid credentials → { "error": "Invalid credentials" }

Question 17: Rate Limiting

Task: Implement rate limiting that allows maximum 10 requests per minute per IP address.

Expected Output:

First 10 requests → Success (200)
11th request → Status: 429, { "error": "Too many requests" }

Question 18: Request Timeout

Task: Create an endpoint that processes data with a 5-second timeout. Return timeout error if exceeded.

Expected Output:

Process completes in < 5s → Returns result
Process takes > 5s → Status: 408, { "error": "Request timeout" }

Question 19: Data Transformation Middleware

Task: Create a middleware that transforms response data by adding a timestamp field to all responses.

Expected Output:

All responses include: { ..., "timestamp": "2025-01-15T10:30:00.000Z" }

Question 20: Nested Routes

Task: Create nested routes /api/users/:userId/posts that returns all posts for a specific user.

Expected Output:

GET /api/users/1/posts → Array of posts belonging to user with ID 1

Question 21: Conditional Middleware

Task: Create middleware that only runs for specific routes (e.g., only for /api/admin/* routes).

Expected Output:

Request to /api/admin/users → Middleware executes
Request to /api/users → Middleware skipped

Question 22: Response Compression

Task: Implement response compression for all responses to reduce payload size.

Expected Output:

Response headers include: "Content-Encoding: gzip"
Response body is compressed

Question 23: Request ID Middleware

Task: Create middleware that generates a unique request ID for each request and includes it in response headers.

Expected Output:

Response headers include: "X-Request-ID: abc123-def456-ghi789"

Question 24: Database Transaction

Task: Create an endpoint that performs multiple database operations in a transaction. Rollback on error.

Expected Output:

All operations succeed → All changes committed
Any operation fails → All changes rolled back, error returned

Question 25: Webhook Endpoint

Task: Create a POST endpoint /api/webhook that receives webhook data, validates a signature, and processes the payload.

Expected Output:

Valid signature → Processes payload, returns 200
Invalid signature → Returns 401, { "error": "Invalid signature" }

Hard Level Questions

Question 26: Multi-tenant API

Task: Create an API that supports multiple tenants. Each request should be scoped to a specific tenant based on a header or subdomain.

Expected Output:

Request with X-Tenant-ID: tenant1 → Returns data for tenant1
Request with X-Tenant-ID: tenant2 → Returns data for tenant2
No tenant ID → Returns 400 error

Question 27: GraphQL Endpoint

Task: Implement a GraphQL endpoint that allows querying users and their posts with relationships.

Expected Output:

Query:
{
  user(id: 1) {
    name
    email
    posts {
      title
      content
    }
  }
}
Returns: User with nested posts data

Question 28: WebSocket Server

Task: Create a WebSocket server that broadcasts messages to all connected clients and handles client connections/disconnections.

Expected Output:

Client connects → Server logs connection
Client sends message → All connected clients receive message
Client disconnects → Server logs disconnection

Question 29: Background Job Queue

Task: Implement a job queue system that processes tasks asynchronously. Create endpoints to add jobs and check job status.

Expected Output:

POST /api/jobs → Returns job ID
GET /api/jobs/:id → Returns job status (pending/processing/completed/failed)

Question 30: API Versioning

Task: Implement API versioning using URL paths (/api/v1/users, /api/v2/users) with different response formats.

Expected Output:

GET /api/v1/users → Returns old format
GET /api/v2/users → Returns new format with additional fields

Question 31: Caching Layer

Task: Implement Redis caching for a frequently accessed endpoint. Cache for 5 minutes, invalidate on updates.

Expected Output:

First request → Fetches from database, caches result
Subsequent requests (within 5 min) → Returns from cache
After 5 min → Cache expires, fetches fresh data

Question 32: Distributed Locking

Task: Implement a distributed lock mechanism to prevent concurrent processing of the same resource.

Expected Output:

First request acquires lock → Processes resource
Concurrent request → Waits or returns "Resource locked" error
Lock released → Next request can acquire lock

Question 33: Event-Driven Architecture

Task: Create an event emitter system where actions trigger events that multiple listeners can subscribe to.

Expected Output:

User created event → Triggers email service, logging service, analytics service
All subscribers receive and process the event

Question 34: API Gateway Pattern

Task: Implement an API gateway that routes requests to different microservices based on the path.

Expected Output:

/api/users/* → Routes to user-service
/api/products/* → Routes to product-service
/api/orders/* → Routes to order-service

Question 35: Circuit Breaker Pattern

Task: Implement a circuit breaker that stops calling a failing service after 5 failures, opens circuit, and retries after timeout.

Expected Output:

Service fails 5 times → Circuit opens
Subsequent requests → Immediately returns error without calling service
After timeout → Circuit half-open, allows one test request

Question 36: Request Batching

Task: Create an endpoint that accepts multiple requests in a single batch and processes them efficiently.

Expected Output:

POST /api/batch
Body: [
  { "method": "GET", "path": "/users/1" },
  { "method": "GET", "path": "/users/2" }
]
Response: Array of results for each request

Question 37: Database Connection Pooling

Task: Implement connection pooling with a maximum of 10 connections. Handle connection exhaustion gracefully.

Expected Output:

Up to 10 concurrent requests → All processed
11th request → Queued or returns "Service temporarily unavailable"

Question 38: API Throttling with Sliding Window

Task: Implement sliding window rate limiting that allows 100 requests per hour per user.

Expected Output:

User makes 100 requests in first hour → All succeed
101st request in same hour → Returns 429
After 1 hour from first request → Window slides, allows new requests

Question 39: Health Check and Readiness Probe

Task: Create endpoints /health and /ready that check server health and database connectivity respectively.

Expected Output:

GET /health → { "status": "healthy", "uptime": 3600 }
GET /ready → { "status": "ready", "database": "connected" }
Database down → /ready returns { "status": "not ready", "database": "disconnected" }

Question 40: Request/Response Interceptor

Task: Create interceptors that log all requests/responses, transform data, and handle errors globally.

Expected Output:

All requests logged with: method, path, headers, body
All responses logged with: status, headers, body
Errors automatically formatted and logged

Question 41: Multi-database Support

Task: Implement an abstraction layer that allows switching between MySQL and PostgreSQL databases based on configuration.

Expected Output:

Config: MySQL → Uses MySQL connection and queries
Config: PostgreSQL → Uses PostgreSQL connection and queries
Same API interface for both

Question 42: API Documentation Generator

Task: Create an endpoint that automatically generates API documentation from route definitions and returns OpenAPI/Swagger spec.

Expected Output:

GET /api-docs → Returns OpenAPI JSON specification
GET /api-docs/ui → Returns Swagger UI interface

Question 43: Request Deduplication

Task: Implement request deduplication that prevents processing the same request multiple times within a time window.

Expected Output:

Duplicate request within 1 minute → Returns cached response
Unique request → Processes normally

Question 44: Distributed Tracing

Task: Implement distributed tracing that generates trace IDs and logs them across multiple service calls.

Expected Output:

Request generates trace ID: "trace-abc123"
All service calls include trace ID in logs
Can trace full request path across services

Question 45: Graceful Shutdown

Task: Implement graceful shutdown that stops accepting new requests, completes ongoing requests, and closes connections properly.

Expected Output:

SIGTERM received → Stops accepting new requests
Completes all ongoing requests
Closes database connections
Server shuts down gracefully

Practice Tips

  1. Start with Easy questions to build confidence
  2. Focus on syntax and structure - pay attention to proper formatting
  3. Test your solutions - verify outputs match expected results
  4. Time yourself - practice under interview conditions
  5. Review your code - look for improvements and best practices

Need More Practice?

Enroll in the NodeJS Backend Cohort @ ₹699 on https://learn.aakashdev.in/

Get hands-on experience with real projects, expert mentorship, and comprehensive backend development training!


Join Our Community

Stay connected and keep learning:

Join our WhatsApp Group

Follow me on Instagram

Follow me on X

← Back to Home