● Stage 00 • Prerequisite

HTTP Server & Database Latency

Build an HTTP service connected to a relational database. Measure the latency difference between memory lookups and disk reads under concurrent client load.

First steps

  1. Create GET /mem/hello with your language's HTTP library.
  2. Return a fixed JSON value. Check the response with curl.
  3. Replace the fixed value with a map. Add the database after reads and writes work.
Project Goal
Skills Acquired
HTTP/1.1 Framing Connection Pooling Parameterized SQL Thread Safety & Mutexes wrk Latency Profiling p99 Latency Analysis
Technical Specification
Milestones
00.1
HTTP Request Router & JSON Handling
Parse request paths, query parameters, and JSON payloads. Return status codes 200, 201, 400, and 404 with Content-Type: application/json.
00.2
Database Connection Pool
Configure a connection pool with maximum 25 connections to PostgreSQL or SQLite. Execute parameterized queries for insert and select operations.
00.3
Thread-Safe Memory Map
Maintain an in-memory hash map protected with a read/write mutual exclusion lock. On insert, write to both database and memory map. Endpoint GET /mem/:key reads from memory only.
00.4
Concurrent Latency Benchmark
Load 50,000 records into the database. Run wrk with 50 concurrent connections for 30 seconds. Record requests per second and p50, p90, and p99 latency for both endpoints.
Verification Commands

Start your server and load the records first, including key_100. Install wrk for these checks; use its latency output to compare the same key on both paths.

# 1. Benchmark in-memory read endpoint
wrk -t4 -c50 -d30s --latency http://localhost:8000/mem/key_100

# 2. Benchmark database read endpoint
wrk -t4 -c50 -d30s --latency http://localhost:8000/db/key_100
Acceptance Criteria
The server must process 10,000 requests with zero dropped connections or 5xx errors. The generated test log must show measured p50 and p99 latency deltas comparing memory lookups to disk database queries.
← Track Index Stage 01: Redis Clone →