Overview
Problem
Venue operators and vendors need predictive operations rather than only historical dashboards. The system must forecast upcoming venue pressure and recommend safe, low-risk actions before losses occur, while remaining auditable and explainable.
Users
Venue operators, vendors, platform engineers, and compliance reviewers. Source data comes from ESP32 sensor nodes, POS feeds, and external context APIs.
Success criteria
- Durable, replayable Kafka-compatible event backbone with versioned schemas
- Stateless, idempotent services suitable for horizontal scaling on AWS
- Short-horizon forecasts and advisory recommendations with confidence and explanations
- Live vendor-console updates via Server-Sent Events
- Reproducible cloud deployments via Terraform and GitHub Actions
- End-to-end observability: traces, metrics, logs, and dashboards
Constraints
- Distributed: services communicate primarily through durable domain events; synchronous protocols reserved for request-response paths
- Safety: actuation is restricted to advisory, low-risk signals (no safety-critical automation)
- Governance: schemas, contracts, and infrastructure-as-code are versioned and validated in CI
- Security: TLS everywhere, per-device credentials, secrets kept in a managed secret store, container and IaC scanning in CI
- Reliability: idempotent consumers, out-of-order tolerance, dead-letter handling, and event replay
- Portability: local Docker Compose mirrors the cloud topology so the same artifacts run dev → staging → production
System architecture
Layered, event-driven system. Four layers fan into a central Kafka-compatible domain-event bus: (1) an External Digital Sources layer pulled in over HTTPS by Go adapter services; (2) a Physical IoT Layer of ESP32 nodes communicating over MQTT through a broker and IoT Gateway; (3) a Microservices Core in Go plus an Applied-AI service in Python; and (4) a User Interface Layer where a React + TypeScript vendor console talks to a Go API Gateway over REST and SSE. A shared Data Layer (PostgreSQL, TimescaleDB, Redis, S3 / MinIO) backs the services.
External Digital Sources
Read-only third-party APIs (weather, transit, calendar, POS, traffic) consumed over HTTPS by Go adapter services with timeout, retry, and stale-response protection.
Physical IoT Layer (ESP32)
ESP32 nodes covering counting, weight, presence, and environmental sensing publish telemetry to an MQTT broker over TLS. A separate actuator node receives advisory commands.
MQTT Broker + IoT Gateway
MQTT broker fronted by a Go IoT Gateway that validates and normalizes device payloads into domain events, rejects malformed payloads, and tracks device heartbeats.
Kafka-Compatible Event Bus
Durable event backbone for telemetry, forecast, recommendation, and audit streams. Versioned schemas validated in CI; dead-letter handling and offset-based replay for recovery.
Microservices Core (Go)
Stateless, idempotent Go services own bounded contexts and communicate through events. The service boundary evolves as load and domain edges mature.
AI Forecast Service (Python)
FastAPI service that consumes domain events and publishes forecasts and recommendations with confidence and explanations. Experiments and models tracked in MLflow; artifacts persisted to object storage.
API Gateway (Go)
REST over TLS for configuration and historical reads; SSE streams that push live forecasts and operational state to the vendor console.
Vendor Console (React + TypeScript)
Responsive SPA for desktop and tablet that renders forecasts, operational pressure, sensor health, recommendations, and an audit timeline.
Data Layer
PostgreSQL for operational state, TimescaleDB for time-series telemetry, Redis for hot state and SSE fan-out, S3 / MinIO for model artifacts, MLflow for experiment lineage.
Data
Source
ESP32 sensor telemetry over MQTT; external context APIs (weather, transit, calendar, traffic); POS or simulated POS feed.
Labeling
Forecasting uses historical and simulated venue activity. Schema validation runs at every dataset boundary. Sensitive identifiers are excluded from the MVP data model.
Quality checks
- Schema validation at every event boundary
- Schema validation for ML training and inference inputs
- Sensor freshness and staleness detection at the IoT Gateway
- Dead-letter handling with replay tooling for poison events
Leakage prevention
Time-based train / validation splits; held-out windows per venue; no future-event leakage into feature pipelines; event timestamps anchored to event-time, not processing-time.
Model / core logic
Baseline
Naive seasonal baselines (hour-of-day, day-of-week) and simple rule-based heuristics serve as the comparison floor for the Applied-AI forecasting service.
Iterations
- Governance and engineering workflow: repository structure, ADRs, CI scaffolding, documentation standards, and review process before service implementation begins
- Local foundation: Docker Compose topology, shared domain model, event contracts, and service skeletons with health checks
- Ingestion and event backbone: MQTT → IoT Gateway → Kafka-compatible bus with idempotent, replayable consumers
- Persistence and surface: PostgreSQL / TimescaleDB / Redis persistence, REST + SSE API surface, React vendor console
- Applied AI and actuation: Python forecasting service with experiment tracking, plus an advisory recommendation / actuation workflow
- Observability and delivery: OpenTelemetry traces, metrics, dashboards, CI/CD security gates, Terraform AWS environments, and a staging / production promotion workflow
Why this approach
A Kafka-compatible event backbone plus stateless services keeps forecasting, persistence, and UX concerns independently scalable, idempotent, and replayable. Go gives predictable performance for ingestion and processing; Python keeps the Applied-AI toolchain ergonomic; React + SSE keeps the operator UX responsive without overcommitting to bidirectional protocols. The phased plan delivers a working slice early and adds reliability, observability, and cloud promotion in deliberate steps.
Evaluation
Offline metrics
- Forecast error (MAE / MAPE) per horizon and per venue, with calibrated confidence scores
- Schema validation pass-rate at every event and dataset boundary
- Contract-test coverage for REST and event schemas, with backward-compatibility checks in CI
Production monitoring
- Service-level objectives for end-to-end telemetry latency, API read latency, and consumer-group lag
- Reliability indicators for actuator acknowledgements, dead-letter rates, and sensor heartbeat freshness
- Distributed traces propagated across MQTT, the event bus, REST, and gRPC via W3C Trace Context (OpenTelemetry → Prometheus / Tempo / Loki / Grafana)
Deployment
Packaging
Per-service Docker images built and scanned in GitHub Actions; local development orchestrated by Docker Compose; cloud deployment as managed container services. Terraform modules separated by concern (network, compute, data, observability) with remote state and locking.
API
REST over TLS for configuration and historical reads; SSE for one-way live updates to the vendor console; MQTT for device I/O; internal gRPC where synchronous service-to-service calls are required.
Scaling
Stateless services scale horizontally on managed container compute; event topics partitioned by tenant with consumer groups; TimescaleDB handles time-series load with retention and compression; Redis caches hot state for low-latency SSE fan-out.
Versioning
Versioned event schemas and service contracts validated in CI (backward-compatible by default; breaking changes introduce a new event type). Semantic versioning on services; ADRs record significant architecture decisions.
Rollback
Image-tag pinning enables instant rollback; staging and production gated by manual approval plus smoke / canary checks; event replay from bus offsets recovers downstream projections after defects.
Safety & privacy
PII handling
PII is minimized: the MVP stores no customer faces, names, or personal device identifiers. Out of scope: emergency response, crowd-control enforcement, access control, payment authorization, medical decisions, facial recognition, and any public-safety actuation. Forecasts are advisory; the system does not make safety-critical decisions.
Security
- TLS on all external, inter-service, and device channels
- OAuth 2.0 / JWT authentication with role-based access control
- Per-device credentials with revocation, enforced at the broker
- Secrets stored in a managed secret store (never committed to source)
- Container, dependency, and IaC scanning in CI; pipelines fail on critical findings
- IAM least privilege; private subnets for stateful services; branch protection and required reviews on the main branch
- Threat model and runbook maintained alongside the SRS
Results
- Phase 0 complete: SRS baselined to ISO/IEC/IEEE 29148 with architecture views per ISO/IEC/IEEE 42010 and quality attributes per ISO/IEC 25010; ADRs 001–007, CI scaffolding, pre-commit hooks, CODEOWNERS, and contributor governance in place
- Phase 1 complete: full local Docker Compose stack running Postgres/TimescaleDB, Redis, Mosquitto MQTT, MinIO, Redpanda (8 topics + DLQ), MLflow with Postgres backend and MinIO artifacts, and observability stack (Prometheus, Grafana, Loki, Tempo) behind a Compose profile
- Makefile-driven developer workflow with make doctor preflight, make up / make up-full, and CI pipeline for lint, compose-validate, and env-drift checks
- Versioned event schemas shipped: domain event envelope and telemetry schemas for footfall counting and stock weight, with pytest validation harness
- ADR-008 records local stack composition decisions; runbook documents all service URLs, credentials, and troubleshooting steps
What I would do next
- Land backend service skeletons: Go API gateway, IoT gateway, and event processor with health checks and shared domain model
- Wire end-to-end ingestion: MQTT → IoT Gateway → Redpanda bus with idempotent, replayable consumers and persistence to Postgres/TimescaleDB/Redis
- Expose REST + SSE API surface and ship the React vendor console with live forecast streaming
- Ship the Python Applied-AI forecasting service with MLflow experiment tracking and confidence-scored recommendations
- Light up full CI/CD security gates and Terraform AWS environments with staging / production promotion workflow