L3: Orders extraction example — standalone service using same domain code#6
Open
maurcarvalho wants to merge 6 commits intomainfrom
Open
L3: Orders extraction example — standalone service using same domain code#6maurcarvalho wants to merge 6 commits intomainfrom
maurcarvalho wants to merge 6 commits intomainfrom
Conversation
added 6 commits
February 24, 2026 16:40
…ain code - apps/orders-service/src/main.ts: standalone HTTP server using libs/modules/orders - apps/orders-service/Dockerfile: multi-stage build for the extracted service - apps/orders-service/tsconfig.json: extends root, includes shared libs - apps/orders-service/project.json: Nx project config - Dockerfile (root): monolith build - docker-compose.l3.yml: both services running (orders-db + main-db + redis) Zero domain code duplication. The handlers, entities, and value objects are identical to the monolith. Only infrastructure wiring differs.
The extracted Orders process is a worker that listens for events and publishes events. The monolith (or API gateway) continues to serve REST endpoints. An HTTP layer can be added later if the module needs an independent API surface (separate team, SLA, deployment cadence).
L3 means fully independent: the extracted Orders service serves its own HTTP API on port 3001, owns its database, and registers its own event listeners. This is the whole point of extraction.
- Add Next.js middleware: rejects /api/orders/* with 410 Gone when EXTRACTED_MODULES=orders is set - Update register-listeners.ts: skip orders listeners when extracted - Set EXTRACTED_MODULES=orders in docker-compose.l3.yml monolith service Extraction is a configuration change, not a code change.
Each module defines its own registerXxxListeners() function. The orchestrator loops MODULE_REGISTRARS, skipping any module listed in EXTRACTED_MODULES. Adding or extracting a module is a one-line change in one place.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
L3: Selective Extraction — Orders as Independent Service
Demonstrates the L3 level of progressive scalability: extracting the Orders module into a fully independent service while the monolith continues serving inventory, payments, and shipments.
What's added
Orders Service (
apps/orders-service/)libs/modules/orders/— zero code duplicationMonolith Extraction Support
EXTRACTED_MODULESenv var controls which modules are extracted410 Goneregister-listeners.tsskips extracted module listenersDocker Compose (
docker-compose.l3.yml)orders-service: standalone process (port 3001) with dedicated DBmonolith: remaining modules (port 3000) withEXTRACTED_MODULES=ordersorders-db: dedicated PostgreSQL for Ordersmain-db: shared PostgreSQL for remaining modulesredis: shared infrastructure (cache + queues)Key design decisions
@tiny-store/modules-ordersEXTRACTED_MODULES=ordersand the monolith serves orders againTesting
All 33 existing tests pass. No domain logic was changed.