Tiny Flask service for on-device image classification with a bounded queue + fail-fast overload.
This is a small edge inference server I run on a Pi. It takes a base64 image, runs MobileNetV2, and returns top-5 predictions. Main thing I cared about was making overload behavior obvious (bounded queue + 503 instead of slow timeouts).
Also has an optional EDGE_MODE=tier1 that exports telemetry batches to a local “control plane” receiver.
- Python 3.9–3.11 (tensorflow 2.15)
- Flask + requests
- TensorFlow (MobileNetV2), Pillow, numpy
POST /inferreturns top-5 + latency- bounded FIFO queue (
QUEUE_SIZE, default 10). queue full → 503 right away - single worker thread (simple + predictable)
/health,/status,/metrics- tier1 mode: telemetry batches + disk spool if control plane is down
python3 -m venv venv && source venv/bin/activate
pip install -r requirements.txt
python3 src/app.py
python3 tests/demo.pyTier1 local demo (starts fake control plane + edge + runs demo + load burst):
./scripts/demo_tier1.shclient -> Flask (/infer) -> bounded queue -> worker -> model -> response
|-> /health /status /metrics
|-> telemetry sender thread (tier1 only)
- switch base64 to multipart uploads
- better metrics (percentiles, not just averages)
- a safer model swap flow (right now it’s restart-based)
- bounded queues are nice because failure is explicit. it’s way easier to debug “503, queue full” than random long tail latency.
- telemetry can’t be on the request path. even “just one post” can hang your service if the network is weird.
- disk spooling is a cheap way to make edge stuff feel real. but you need a cap or you’ll fill storage.
solo project built by Zane Hensley