Subscription Management Service
A production-grade modular monolith. Engineered for strict boundaries, predictable states, and full-stack observability.
What It Is
A complete backend system for managing recurring subscriptions—handling sign-ups, automated billing, renewal scheduling, and notifications. Behind the scenes, it utilizes a robust asynchronous worker pipeline (Asynq/Redis) to process thousands of lifecycles without human intervention, all monitored by an enterprise-grade telemetry stack.
Why It Exists
Subscription state bugs cost real money. When billing systems are built as an afterthought, users get charged after cancelling or stuck in ghost states. I built this architecture to mathematically prove that invalid states can be made impossible at compile-time, and to demonstrate that defensive testing and distributed tracing should be first-class architectural citizens.
Key Decisions
- Interface Segregation — Service interfaces are strictly split into
External(API) andInternal(Workers), physically preventing HTTP controllers from triggering background logic. - Database-Agnostic Transactions — Transactions are executed via an injected
TxnFnclosure, allowing hermetic service unit tests without importing MongoDB drivers into the domain. - Spoofing-Resistant IP Extraction — The system traverses
X-Forwarded-Forstrictly right-to-left to extract the true client IP, actively ignoring attacker-controlled prepended headers. - Asynchronous Task Chaining — Domain mutations and side effects are decoupled. If the SMTP server crashes, Asynq safely retries the email task without re-running the billing transaction.
- Deterministic Clock Injection — Time is injected via a
NowFnclosure rather than relying on global wall-clock drift, enabling mathematically perfect boundary testing for subscription expirations.
Trade-offs & Scope Management
Senior engineering requires deliberate architectural constraints. To maintain boundary integrity, I explicitly enforced:
- Modular Monolith over Microservices — Strict domain separation ensures it can be split cleanly later, but a single deployment binary avoids premature network latency and orchestration overhead today.
- Hermetic Reliability over Speed — Implemented strict trace-correlated logging and isolated Testcontainer database setups. It takes slightly longer to build, but completely eliminates flaky tests.
- Banned Cross-Domain Reads — Services are physically restricted from querying other domains' repositories to prevent schema coupling and enforce strict data boundaries.
Go · MongoDB · Redis · Clean Architecture · Background Workers