A lightweight Go API for monitoring device uptime and upload performance — built for the SafelyYou Fleet Monitoring coding challenge.
This service simulates how SafelyYou tracks device connectivity and upload latency at customer sites.
Each device periodically sends heartbeat and upload stats telemetry to the API, which then calculates:
- Uptime (%) — percentage of minutes the device reported a heartbeat
- Average Upload Time — mean duration for uploads, formatted as a time string (e.g.
3m21.8s)
The implementation adheres to the provided OpenAPI contract (openapi.json) and supports concurrent updates across multiple devices.
├── Dockerfile # Multi-stage build for Go binary
├── docker-compose.yml # Compose config for local orchestration
├── Makefile # Developer convenience commands
├── main.go # App entrypoint + route handlers
├── device_test.go # Unit tests for uptime & averages
├── devices.csv # Device list loaded on startup
├── openapi.json # API spec provided by challenge
├── results.txt # Simulator output for verification
├── device-simulator-linux-amd64 # Provided test utility (excluded from build)
└── .dockerignore # Ignore files for faster builds
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/v1/devices/{device_id}/heartbeat |
Record a heartbeat timestamp |
POST |
/api/v1/devices/{device_id}/stats |
Record upload stats (in ns) |
GET |
/api/v1/devices/{device_id}/stats |
Retrieve uptime and average upload time |
make run
go run main.go
docker build -t safelyyou-fleet .
docker run -p 6733:6733 safelyyou-fleet
docker compose up
The service will be available at http://localhost:6733
Unit tests are included for the uptime % and mean upload time calculation functions
make test
To verify the service against the official simulator:
make simulate
############ RESULTS #################
[device-simulator] 2025/10/19 18:56:28
DeviceID: 38-4e-73-e0-33-59
Uptime
Expected: 99.79167
Actual: 99.58420
AvgUploadTime
Expected: 3m29.226522788s
Actual: 3m29.226522788s
Minor rounding differences are expected and acceptable per spec.
- Uses Go 1.23’s standard library only (no external deps).
- Thread-safe per-device state with sync.Mutex.
- Graceful shutdown using context and os/signal.
- Fast, stateless, in-memory computation.
make runRun app locallymake buildBuild binary into bin/make testRun unit testsmake tidyClean Go modulesmake cleanRemove build artifactsmake simulateRun device simulator
- Multi-stage build (builder → runtime)
- Produces a minimal Alpine-based image
- Runs as non-root appuser
- Exposes port 6733
- Builds from local Dockerfile
- Runs the service on port 6733
- Automatically restarts unless stopped
Run it:
docker compose up
Optimized to exclude project artifacts, including:
- device-simulator-linux-amd64
- results.txt
- bin/
- .git/
- .vscode/
- README.md
- Makefile
To move this prototype toward a production service:
- Persistent Storage – Replace in-memory maps with a database (e.g., PostgreSQL or Redis) so data survives restarts and scales horizontally.
- Monitoring & Alerts – Expose /healthz and /metrics endpoints for Prometheus/Grafana and trigger alerts when devices miss heartbeats or uploads slow down.
- Scalability & Resilience – Run behind a load balancer with multiple stateless API instances; use queues or pub/sub to handle bursty telemetry.
- Security & Configuration – Add HTTPS, API key authentication, and environment-based configuration management.
Michael Diener
Software Engineer
Built with ❤️ and Go for the SafelyYou Fleet Monitoring challenge (2025)