ENGINEERING CASE STUDY

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).

O(1) Memory CSV Streaming for 100k+ Rows
< 0.1 ms Hybrid L1 Caffeine + L2 Redis Cache
54 Tests Testcontainers Postgres 15 & Load
V1–V11 Flyway Migrations & K8s HPA (3–10)

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:

Stage 01

REST Controller

ISO Validation & Records

Stage 02

Service Layer (ZoneId & O(N) Linear Scan)

Stage 03

CompositeCacheManager

L1 Caffeine / L2 Redis

Stage 04

JPA Projections & Stream<T>

fetchSize=500

Stage 05

PostgreSQL 15

Flyway V1–V11 & Composite Indexes

Key Engineering Decisions & Performance Optimizations

Engineering ChallengeAnti-Pattern AvoidedProduction Solution Implemented
High-Volume CSV ExportLoading entire List<Pedido> into JVM Heap prior to serializationStream<DailySalesProjection> with @Transactional(readOnly = true), @QueryHints(fetchSize = "500"), and chunked StreamingResponseBody I/O
Longest Sales Gap DetectionNested O(N^2) loops comparing date pairs in memorySingle-pass O(N) linear scan over sorted distinct sale dates in MaiorIntervaloSemVendasService
Multi-Timezone ConsistencyAd-hoc timezone conversions scattered across Controllers and SQLUniform LocalDateTime persistence with ZoneId boundary conversion strictly isolated inside the Service layer (Mon–Sun weekly averages & min-sales day)
Relational Selectivity & PayloadFull 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 CachingHard network round-trip dependency on every hot analytical readCompositeCacheManager 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): GlobalTestBootstrap automatically spins up postgres:15-alpine via 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 (54 unit, integration, validation, and load tests).
  • Container Hardening & Kubernetes (HPA + RPO/RTO): Multi-stage Dockerfile (eclipse-temurin:17-jre-alpine, non-root user, dumb-init PID 1 signal handling, G1GC, and MaxRAMPercentage=75%), k8s/ manifests with HorizontalPodAutoscaler (3 to 10 pods), StatefulSets, and an automated PostgreSQL backup/restore CronJob backed 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.
Inspect Source Code, Flyway Migrations & K8s Manifests on GitHub

Open repository featuring GitHub Actions CI (Java 17 + Testcontainers + Docker Build), per-story specs, QA test report, and Disaster Recovery runbook.