Implement a minimal local HTTP server

Quick Overview

This question evaluates proficiency in network programming, HTTP/1.1 protocol parsing, concurrent server design, request routing and security (including path traversal protection), observability, testing, and graceful shutdown using only the language standard library.

Implement a minimal local HTTP server

Company: Rippling

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Onsite

Implement a minimal local HTTP server from scratch (no frameworks). Requirements: listen on a configurable port, parse HTTP/1.1 requests, support GET and POST, route two endpoints (/health returning 200 OK; /echo returning the request body), serve static files from a directory with correct Content-Type, handle concurrent connections, request timeouts, graceful shutdown, and structured request logging. Return appropriate errors (400/404/ 405). Include unit tests and clear run instructions for local development.

Overview: This question evaluates proficiency in network programming, HTTP/1.1 protocol parsing, concurrent server design, request routing and security (including path traversal protection), observability, testing, and graceful shutdown using only the language standard library.

|Home/System Design/Rippling
Rippling logo
Rippling
Sep 6, 2025
hardSoftware EngineerOnsiteSystem Design
24
0

Build a Minimal Local HTTP/1.1 Server (No Frameworks)

Context

You are asked to implement a minimal HTTP/1.1 server from scratch using only the standard library (no web frameworks). The server should run locally, be configurable, and handle concurrency and shutdown cleanly. Include unit tests and clear run instructions.

Requirements

  1. Configuration
    • Listen on a configurable host and port.
    • Serve static files from a configurable root directory.
  2. Protocol and Methods
    • Parse HTTP/1.1 requests: request line, headers, and optional body.
    • Support methods: GET and POST.
    • Return appropriate errors: 400 (Bad Request), 404 (Not Found), 405 (Method Not Allowed).
  3. Routing
    • GET /health → returns 200 OK with body "OK".
    • POST /echo → returns the request body verbatim, with Content-Type preserved if present.
    • Static files: for any other GET path, serve files from the configured root directory.
      • Use correct Content-Type for common file extensions.
      • Protect against path traversal attacks (e.g., ".." segments).
  4. Concurrency and Reliability
    • Handle multiple concurrent connections.
    • Per-connection request timeout.
    • Graceful shutdown (e.g., on SIGINT/SIGTERM): stop accepting new connections and allow in-flight requests to finish.
  5. Observability
    • Structured per-request logging (e.g., JSON lines) including: timestamp, remote address, method, path, status, duration, bytes in/out, and user agent.
  6. Testing and Docs
    • Include unit tests that verify the core behaviors.
    • Provide clear run instructions for local development.

Constraints

  • Use only the language standard library. No web frameworks (e.g., Flask, Express, Spring), no third-party libraries.
  • Keep the implementation minimal but robust enough for the above requirements.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...