as

Projects / simhttp

simhttp

A fake HTTP backend. Hotwire needs something to route to, and I did not want that something to be Envoy or a real service.

Why

The control plane is the part I wanted to see move. The data plane should be boring and dishonest on purpose: I set the latency, the jitter, and the error rate, then watch the weights change. A real backend would mix those knobs with whatever else the process is doing.

Diagrams

A solid outline is the path in the repo. A dashed outline is the alternative that shape is refusing.

Flags set latency, jitter, and error rate. The library serves HTTP and snapshots p50, p99, error rate, inflight, and RPS. A hotwire backend is a thin wrapper that streams that snapshot.

flowchart TD
  flags["Latency, jitter, and error flags"]
  lib["simhttp library"]
  snap["Snapshot"]
  wrap["Hotwire backend wrapper"]
  flags --> lib --> snap --> wrap
  class flags,lib,snap,wrap chosen
          

The fake server is its own module so go test can check latency without gRPC. Hotwire’s score reads p99 and error rate. The other fields stay on the snapshot for a later formula, without a new RPC.

flowchart TD
  q{Where the fake server lives}
  q -->|"tests without a gRPC server"| lib["A library"]
  q -->|"a demo switch inside hotwire"| flag["A demo flag"]
  use{Fields on the snapshot}
  use -->|"the formula today"| used["p99 and error rate"]
  use -->|"present, not read"| later["p50, inflight, and RPS"]
  class lib,used,later chosen
  class flag rejected
          

Why this shape

It is a library, not a demo flag inside hotwire. go test can check the latency and the metric snapshot without a gRPC server in the way. A hotwire backend is a thin wrapper that streams the snapshot: p50, p99, error rate, inflight, and RPS.

The score in hotwire uses p99 and error rate. The other fields are still on the snapshot, because the backend already knows them and the control plane can start reading them later without a new protocol. minstd is the pile of stdlib shims I pulled out while writing this HTTP stack. It is not a second standard library.

Where it breaks

The numbers are whatever the flags say. A wrapper that reports them honestly is still trusted by the proxy, which never times the HTTP call it just forwarded. That is fine while I am the one setting --latency. It is the first lie that matters if the backend is not simhttp.