Consolidating Fragmented Services into a NestJS Modular Monolith at Vokraf: 50% Lower Cloud Cost, 80% Faster Releases
- PeranRole
- Fullstack Developer (Architecture Lead)
- DurasiTimeline
- ~1 Year · Live Production
- Skala SistemSystem Scale
- 200K+ Users · 99.9% Uptime
Consolidated container apps, compute, and server storage
Replaced manual standby deploys with GitHub Actions
Held steady throughout and after phased consolidation
Migrated incrementally without stopping live operations
Ringkasan arsitektur platform Vokraf setelah konsolidasi ke modular monolith NestJSVokraf platform overview after consolidating into a NestJS modular monolith
This case study documents how I led the consolidation of Vokraf’s learning management platform from fragmented servers and repositories into a single NestJS modular monolith, while keeping production availability at 99.9% uptime.
As the Fullstack Developer leading this architecture effort at Vokraf, the problems in front of us were concrete: cloud bills kept rising across too many separate servers, deployments relied on manual steps with engineers on standby, and maintaining too many repositories with a small team let technical debt pile up until the application became noticeably slow.
Over roughly one year of incremental migration in live production, consolidating into a single NestJS modular monolith cut our monthly cloud infrastructure bill by 50% and shortened release cycles by 80%, while keeping uptime steady at 99.9%.
1. Baseline and Root Causes
Before the consolidation, Vokraf was not running a formal Kubernetes microservices setup behind a unified API gateway. In practice, the backend consisted of many separate servers deployed across multiple container apps.
That fragmentation came from rapid earlier growth, including the Kartu Prakerja era when the platform passed 200,000 registered learners. Along the way, several domain splits and partial migrations were started and left unfinished. As a result, the frontend talked directly to each individual server, while all of those servers still shared a single PostgreSQL database.
That fragmented layout created three recurring problems.
Cloud cost inflation and fragmented resources
Even though every server connected to the same PostgreSQL database, each split service still required its own container app, compute instance, and server storage footprint on Alibaba Cloud and DigitalOcean. Idle capacity piled up across small instances while monthly compute and storage costs kept climbing.
Repository sprawl, compounding tech debt, and slow application logic
Because the frontend called each server directly without an internal gateway, cross-service network hops were not the bottleneck. The real performance problem came from maintenance overhead: a small engineering team had to maintain too many separate repositories. Product changes were patched across repos under deadline pressure without time to clean up older code. Technical debt compounded, business logic grew convoluted, and PostgreSQL queries became inefficient, making the application sluggish.
Manual releases prone to regression
Deployments still depended on manual intervention, with engineers staying on standby during release windows. Coordinating manual releases across multiple repositories without an automated pipeline kept the risk of human error and regressions high on every update.
The operational overhead drained engineering time, and our cloud spend was out of proportion to the size of the team maintaining the platform.
2. Architectural Decision Record (ADR) and Trade-off Analysis
To fix both infrastructure waste and compounding technical debt, we weighed two realistic options: finish separating the multi-service setup and keep maintaining multiple repositories and servers independently, or consolidate everything into a single modular monolith.
Finishing the multi-service split would have forced a small team to keep maintaining many repositories, duplicate shared conventions across services, and pay for separate container apps and compute instances. That worked directly against both our cost and maintainability goals. We chose to consolidate all services into one NestJS Modular Monolith packaged with Docker and Docker Compose.
ADR Summary: Consolidate Services into a NestJS Modular Monolith
- Status: Accepted.
- Context: Fragmented container apps and compute instances from unfinished past migrations inflated cloud spend, while maintaining too many repositories with a small team caused technical debt to pile up and slowed down the application.
- Decision: Consolidate all split services into a single NestJS modular monolith deployed via Docker and Docker Compose on Alibaba Cloud and DigitalOcean.
- Consequences: Cut server compute and storage costs by 50%, focused the entire team on one unified repository, enabled coordinated refactoring of slow logic and queries, and required strict module boundaries inside the codebase.
Architecture Trade-off Comparison
| Evaluation Dimension | Fragmented Multi-Server & Repos | Consolidated Modular Monolith (NestJS) |
|---|---|---|
| API surface & maintenance | Frontend called separate servers directly; duplicated logic and tech debt spread across many repos | Unified API surface with isolated NestJS modules and consistent business logic |
| Server allocation efficiency | Many container apps, compute instances, and split server storage with repeated idle footprints | Unified compute allocation that can be right-sized cleanly |
| Domain boundaries | Physically split across repos and containers from unfinished migrations | Clear logical boundaries enforced via NestJS module encapsulation and Clean Architecture |
| Deployment complexity | Multiple build artifacts and separate manual deploys per repository | Single Docker image released atomically through CI/CD |
| Negative trade-off & mitigation | Tech debt compounded in legacy repos rarely touched by a small team | Risk of cross-module code coupling; mitigated with strict module boundaries and automated tests |
For a team of our size, consolidating into a modular monolith was the pragmatic call. NestJS modules and dependency injection let us keep domain logic cleanly separated without paying the maintenance tax of scattered repositories and servers.
3. Success Metrics and Stop Conditions
To make sure cost reduction never came at the expense of product stability or engineering speed, we set four quantitative targets up front:
- Cut monthly cloud infrastructure spend (compute servers and storage) by at least 50%.
- Keep production availability at 99.9% uptime throughout and after the consolidation.
- Improve endpoint response times by clearing accumulated tech debt, simplifying application logic, and tuning PostgreSQL queries.
- Reduce release cycle time by up to 80% through full CI/CD automation.
We also defined two stop conditions to keep optimization grounded:
- Service quality floor: server downsizing could never drop uptime below 99.9% or degrade P95 response latency during peak load.
- Operational headroom: compute downsizing stopped once servers sat within a safe high-load range with no CPU throttling or out-of-memory events.
4. Execution Strategy: Phased Migration in Live Production
The hardest constraint was that Vokraf remained live in production throughout the entire effort. We had to consolidate legacy services while continuing daily maintenance and shipping product features.
Phased migration across 4 stages (~1 year)
To avoid the blast radius of a big-bang rewrite, we executed a four-phase consolidation over nearly a year:
- Phase 1, modular core foundation: set up core NestJS modules (JWT authentication, shared PostgreSQL connections, domain structure), Docker Compose configuration, and automated test pipelines.
- Phase 2, user-facing systems: migrated learner-facing services and core learning flows first, clearing legacy tech debt, simplifying convoluted logic, and rewriting slow PostgreSQL queries along the way.
- Phase 3, internal tools: once user-facing systems proved stable in production, consolidated internal dashboards, content management, and administrative operations.
- Phase 4, consolidation and decommissioning: shut down legacy container apps after full cutover and deleted their supporting compute instances and server storage from our cloud accounts.
Dual-track engineering for ongoing product delivery
To keep business feature delivery moving during the year-long consolidation, we followed two rules. First, every new business feature was built directly as a dedicated NestJS module inside the monolith so we stopped adding weight to legacy repositories. Second, every migrated module went through logic and PostgreSQL query refactoring so performance gains shipped alongside functional migration.
5. Three Pillars of Reliability
Consolidating services into one codebase means a careless change in one module can affect another. We backed the migration with three reliability safeguards.
CI/CD automation with GitHub Actions
Previously, releases were manual and required engineers to stay on standby. We built GitHub Actions pipelines to run linting, TypeScript type-checking, and automated test suites on every pull request. Passing builds produced standardized Docker images and triggered automated deployments to Alibaba Cloud and DigitalOcean. Release time dropped by 80%, and deployments became routine rather than an all-hands event.
Layered automated testing (Jest, Vitest, and Playwright)
We structured automated tests to catch regressions across every layer:
- Unit and logic testing with Jest and Vitest to verify business calculations, payload validation, and data transformations deterministically.
- Integration and functional testing to cover NestJS cross-module interactions, PostgreSQL transactions, and JWT authentication.
- End-to-end (E2E) testing with Playwright to verify critical learner journeys before code reached production.
Observability and resource auditing (ELK Stack & Sentry)
Monitoring handled both incident response and infrastructure right-sizing:
- ELK Stack (Elasticsearch, Logstash, Kibana) centralized structured JSON logs from Docker containers so we could inspect traffic patterns, diagnose anomalies, and trace query performance in real time.
- Sentry captured exceptions and crashes proactively before they spread across users.
- Container CPU, memory, and storage telemetry guided server right-sizing. Whenever metrics showed clear over-provisioning against real load, we scaled instances down to match actual demand.
6. Evaluation Results and Business Impact
After completing all four phases over roughly a year, the before-and-after results were clear across every tracked indicator:
| Key Indicator | Baseline (Fragmented Services) | Final State (Modular Monolith) | Business & Engineering Impact |
|---|---|---|---|
| Monthly cloud cost | High spend from scattered container apps, idle instances, and split storage | Consolidated on right-sized Docker Compose hosts | 50% reduction in server and storage spend |
| Release velocity (CI/CD) | Separate manual deploys requiring engineers on standby | Automated GitHub Actions pipeline with test gates | Up to 80% faster release cycles |
| Availability (uptime) | Exposed to operational drift across many legacy containers and repos | Unified monolith serving a 200,000+ user platform | Steady 99.9% uptime in production |
| Performance & code efficiency | Slow due to compounding tech debt, convoluted logic, and legacy queries | Refactored modular logic and tuned PostgreSQL queries | Measurably faster, more consistent responses |
| Quality assurance | Fragmented manual checks across separate repos | Unified automated test suite (Jest, Vitest, Playwright) | Broad logic coverage preventing functional regressions |
7. Retrospective and Engineering Principles
Running this consolidation over a full year reinforced four principles I still apply to production systems:
- Match architecture to team capacity. Splitting code across many repositories and servers without a large enough team accelerates technical debt. Consolidating into a modular monolith gave a small team room to improve code quality and cut infrastructure cost at the same time.
- Phased execution to limit blast radius. In live production, separating user-facing cutovers from internal tools keeps daily operations safe if issues surface mid-migration.
- Observability as a cost lever. Structured logs in ELK Stack and container resource telemetry turn server right-sizing into a data-backed decision instead of guesswork.
- Automation as the foundation of stability. With every service living in one monolithic codebase, an automated CI/CD pipeline and a thorough test suite are non-negotiable for protecting code integrity and giving the team confidence during regular releases.
Read technical note: From console.log to ELK Stack