Sinatra Mini — High-Throughput Analytics SaaS API in Java 17, Spring 3 & K8s
Multi-Store Sales Analytics SaaS API built with Java 17 and Spring Boot 3.2.12, engineered to eliminate classic Heap OOM, concurrency, and latency bottlenecks in high-volume analytical reporting. The platform evolved through structured engineering governance spanning 49 Epic/Story Issues, 56 Pull Requests, 11 Flyway PostgreSQL migrations (V1–V11), two-tier hybrid caching (Caffeine L1 + Redis L2), Testcontainers integration testing, and Kubernetes HPA (3–10 replicas).
- Public Repository & Releases (
v1.1.0): github.com/evslopes/sinatra-mini - Architectural Evolution Backlog (49 Issues — v1.0 to v3.0): github.com/evslopes/sinatra-mini/issues
Low-Allocation Analytical Execution Pipeline
In multi-store B2B platforms, invoking findAll() or materializing full JPA entity graphs onto the JVM Heap triggers OutOfMemoryError under concurrent reporting loads. The architecture enforces strict layered Single Responsibility (SRP) and processes time-series streams incrementally:
REST Controller
ISO Validation & Records
Service Layer (ZoneId & O(N) Linear Scan)
CompositeCacheManager
L1 Caffeine / L2 Redis
JPA Projections & Stream<T>
fetchSize=500
PostgreSQL 15
Flyway V1–V11 & Composite Indexes
Key Engineering Decisions & Performance Optimizations
| Engineering Challenge | Anti-Pattern Avoided | Production Solution Implemented |
|---|---|---|
| High-Volume CSV Export | Loading entire List<Pedido> into JVM Heap prior to serialization | Stream<DailySalesProjection> with @Transactional(readOnly = true), @QueryHints(fetchSize = "500"), and chunked StreamingResponseBody I/O |
| Longest Sales Gap Detection | Nested O(N^2) loops comparing date pairs in memory | Single-pass O(N) linear scan over sorted distinct sale dates in MaiorIntervaloSemVendasService |
| Multi-Timezone Consistency | Ad-hoc timezone conversions scattered across Controllers and SQL | Uniform LocalDateTime persistence with ZoneId boundary conversion strictly isolated inside the Service layer (Mon–Sun weekly averages & min-sales day) |
| Relational Selectivity & Payload | Full table scans and fat entity hydration (N+1 queries) | Composite index idx_pedido_loja_data (loja_id, data_pedido), database total-sync triggers (V11), and immutable Java 17 Records |
| Resilient Multi-Tier Caching | Hard network round-trip dependency on every hot analytical read | CompositeCacheManager pairing in-process L1 Caffeine (10,000 entries, < 0.1 ms) with distributed L2 Redis (10 min TTL) |
SRE Governance, Testcontainers & Cloud-Native Operations
- Automated Parity Suite (
Testcontainers+ Resilient Fallback):GlobalTestBootstrapautomatically spins uppostgres:15-alpinevia Testcontainers in CI/CD to validate all 11 real Flyway migrations, while seamlessly falling back to an in-memory engine with equivalent Java triggers when offline (54unit, integration, validation, and load tests). - Container Hardening & Kubernetes (
HPA+RPO/RTO): Multi-stageDockerfile(eclipse-temurin:17-jre-alpine, non-root user,dumb-initPID 1 signal handling,G1GC, andMaxRAMPercentage=75%),k8s/manifests withHorizontalPodAutoscaler(3to10pods),StatefulSets, and an automated PostgreSQL backup/restoreCronJobbacked by a documented RPO/RTO runbook. - Multi-Agent Governance & CQRS/Sharding Roadmap: Engineering workflows structured across 4 specialized agent specifications (
.github/agents/: Agile, Engineer, DevOps, and QA) driving a documented 6-Epic Architectural Roadmap toward multi-tenant Sharding and CQRS + Event Sourcing.
Open repository featuring GitHub Actions CI (Java 17 + Testcontainers + Docker Build), per-story specs, QA test report, and Disaster Recovery runbook.