From Monolith to Cloud-Native Microservices: Service Boundaries and High Availability in Practice
A practical guide for backend developers and architects on migrating a monolithic e-commerce system to microservices on the cloud. This article covers split decision criteria, service boundary design, inter-service communication, container elasticity, storage and CDN, observability, and a phased migration strategy using the strangler pattern, with concrete example configurations and thresholds.
From Monolith to Cloud-Native Microservices: Service Boundaries and High Availability in Practice
Audience and Scope
This article is aimed at backend developers and architects evaluating a move from a monolithic system to microservices and cloud-native architecture. The example system is a fictional but realistic mid-sized e-commerce platform; all figures are illustrative and should be replaced with your own business metrics. The article covers seven areas: split criteria, service boundaries, communication, container elasticity, storage and content delivery, observability, and migration cadence.
Example Background
The platform started as a Java monolith containing six modules—product, order, inventory, payment, marketing, and membership—sharing a single MySQL instance. The team of about 40 people is split into 3 groups. Daily order volume is roughly 300,000, with peaks during major promotions reaching 8x the daily average. As the team grew, release frequency dropped from twice a week to once a week, because any module change required full regression testing of the entire system.
1. When to Split
Splitting is not a goal in itself. If two or more of the following conditions hold, splitting usually pays off:
- Two or more teams frequently modify the same codebase, with merge conflicts happening weekly.
- Modules have very different scaling needs—for example, the search service needs 10x the instances of the membership service.
- Modules have different consistency requirements—payment needs strong consistency, while marketing calculations can tolerate eventual consistency.
- A single module’s failure can bring down the whole system, and rate limiting cannot contain the blast radius.
If your team is only 5 people with a few thousand orders per day, a well-modularized monolith is usually the better choice.
2. Defining Service Boundaries
Boundaries should follow business capabilities and data ownership, not technical layers. Each service reads and writes only its own tables; other services access that data through APIs or events.
An example decomposition:
| Service | Responsibility | Data Ownership | Sync API | Published Events |
|---|---|---|---|---|
| Product Service | Product info, categories, listing/unlisting | Product tables, category tables | Query product details | Product listed, product unlisted |
| Inventory Service | Inventory reservation, deduction, restocking | Inventory tables, inventory ledger | Reserve inventory | Inventory insufficient |
| Order Service | Order placement, order state machine | Order tables | Create order | Order created, order canceled |
| Payment Service | Payment records, refunds | Payment tables, refund tables | Initiate payment | Payment succeeded, refund succeeded |
| Marketing Service | Coupons, discount calculation | Campaign tables, coupon tables | Calculate discount | Coupon redeemed |
Boundaries should also be validated against bounded contexts. The concept of a “product” in the marketing service only needs the ID, price, and category—not the full product record. The marketing service can therefore keep a read-only snapshot instead of calling the product service for every field.
3. Inter-Service Communication
Use synchronous calls when an immediate result is required, such as reserving inventory during checkout. Use gRPC or HTTP/JSON with an 800 ms timeout. Enable retries only for idempotent APIs—maximum 2 retries with exponential backoff plus jitter.
Use asynchronous messaging when an immediate result isn’t needed—for example, notifying the marketing service to restore a coupon after an order is canceled. Message broker comparison:
| Dimension | Kafka | RocketMQ | RabbitMQ |
|---|---|---|---|
| Throughput | Very high; suited to logs and behavioral data | High | Moderate |
| Ordering within partition | Supported | Supported | Requires single-queue constraint |
| Transactional messages | Requires an external transaction table | Natively supported | Requires plugin or external solution |
| Dead-letter queue | Must implement yourself | Natively supported | Natively supported |
Choose based on your team’s operational experience and business needs—not on a single metric.
Consumers must be idempotent. A common approach: use the business ID plus event type as a deduplication key, write it to a dedup table first, then execute the business logic. Messages that fail 5 retries go to the dead-letter queue for handling by a compensation job or manual intervention. Configure alerting on dead-letter volume—notify the on-call engineer once it exceeds 10 messages.
4. Containerization and Elastic Scaling
Each service is packaged as an independent image with a fixed version tag—never latest. Images are built once in CI and the same image is reused across environments.
Example resource configuration for the order service: requests of CPU 500m / memory 512Mi, and limits of CPU 1000m / memory 1Gi. Requests set too low cause node overcommit; too high wastes capacity. Tune based on stable load measured under load testing.
Example HPA configuration:
- minReplicas: 3
- maxReplicas: 20
- CPU target utilization: 60%
- Scale-up stabilization window: 60 seconds
- Scale-down stabilization window: 300 seconds
CPU metrics react slowly to traffic spikes. For the order service, per-instance QPS works better as a custom metric, with a target of 80% of the single-instance ceiling measured in load tests. The day before a major promotion, manually raise minReplicas based on predicted traffic and restore it afterward—don’t rely entirely on autoscaling to handle instantaneous peaks.
For releases and rollbacks, keep the last 5 ReplicaSets per deployment. When the error rate exceeds 1% for 5 consecutive minutes, run kubectl rollout undo to roll back to the previous version. The rollback command should be documented in the on-call runbook and verified through drills.
5. Object Storage and Content Delivery
Product images, videos, and merchandising files are stored in private object storage buckets with anonymous access disabled. The frontend accesses them via pre-signed URLs valid for 10 minutes.
Static assets have content hashes in their filenames, e.g. product.a1b2c3.jpg, allowing a CDN cache TTL of 30 days. Assets that can’t be hashed get a 5-minute CDN TTL, and the CDN purge API is called whenever content is updated.
For lifecycle rules: original images not accessed within 90 days of creation are moved to infrequent-access storage to reduce cost. Versioning stays enabled, so accidentally deleted files can be recovered within 30 days.
6. Observability and Stability
Logs, metrics, and traces must share the same request ID to correlate the full path of a single request. Logs are collected into a central log platform and retained for 14 days. Metrics are collected in Prometheus format and retained for 30 days. Trace sampling is set to 1%, but all failed requests and requests slower than 2 seconds are kept in full.
Example SLOs: the order placement API targets 99.9% availability with P99 latency under 800 ms. The error budget is calculated monthly; when remaining budget drops below 20%, non-critical releases are paused.
Example alert rules:
- API error rate above 1% for 5 minutes — phone alert.
- P99 latency above 1.5 seconds for 10 minutes — chat/group alert.
- Dead-letter queue backlog above 10 messages — chat/group alert.
Example circuit breaker rules: if the downstream failure rate exceeds 50% within a 10-second window and request count exceeds 20, the breaker opens. After 30 seconds it moves to half-open, letting a small number of requests through for probing. Fallback plans must be defined before launch—for example, if marketing discount calculation fails, place the order at the original price and record a pending-recalculation flag.
For rate limiting, external APIs are throttled per user ID at 20 requests per second; excess requests receive a 429 response.
Run failure drills at least quarterly, simulating a slow inventory service, an unavailable message queue, and a single availability zone power outage. Record actual recovery times and compare them against SLOs.
7. Migration Cadence
Use the strangler pattern, peeling modules off the monolith one at a time. Each module migrates in this order:
- Clean up module boundaries inside the monolith, removing code that directly accesses other modules’ database tables.
- Launch the new service with dual writes for data sync, while read traffic still hits the old database.
- Reconcile data daily; once the discrepancy rate drops below 0.01%, switch read traffic to the new service.
- Ramp up gradually at 1%, 10%, 50%, and 100%, observing for at least 24 hours at each step.
- Keep the old code for two release cycles, confirm there are no issues, then remove it.
