Skip to content

Simulate Poor Network Conditions

This guide explains how to use the staged toxic proxy setup to simulate poor network conditions when developing Open Data Capture.

When you run scripts/toxic-proxy.sh, it configures Toxiproxy with the following simulated network conditions:

  • Downstream bandwidth limit (API → browser): capped at 5,000 KB/second (~5 MB/s).
  • Upstream bandwidth limit (browser → API): capped at 2,500 KB/second (~2.5 MB/s).
  • Intermittent latency and jitter (downstream):
    • Base latency of 50 ms, plus up to 500 ms of jitter.
    • Applied with 20% toxicity, meaning only about 1 in 5 downstream requests/responses are delayed in this way.
  • Occasional random connection resets (downstream):
    • Connections are randomly reset/closed from the proxy side.
    • Applied with 10% toxicity, so roughly 1 in 10 downstream connections will be abruptly terminated.

Together, these toxics approximate a slow, unstable network where responses arrive slowly, some requests suffer extra delay, and a minority of connections fail unexpectedly.

Prerequisites

  • Install Toxiproxy (both toxiproxy-server and toxiproxy-cli) and ensure they are available on your PATH.

Steps

  1. Set the toxic proxy port in .env

    Choose a port for the toxic proxy (for example 5501) and set:

    • API_DEV_TOXIC_PROXY_PORT=5501
  2. Point the frontend at the toxic proxy

    Update API_BASE_URL to use the same port on localhost:

    • API_BASE_URL=http://localhost:5501
  3. Start the toxic proxy

    Run:

    Terminal window
    scripts/toxic-proxy.sh

    Leave this running. It creates a proxy that sits between the frontend and the API server and applies bandwidth limits.

  4. Launch the app as normal

    In another terminal, run:

    Terminal window
    pnpm dev

Notes

  • The proxy reads API_DEV_SERVER_PORT from .env to know where your API server is listening.
  • If API_DEV_TOXIC_PROXY_PORT is empty, the script exits without starting the proxy.