Unitized Architecture: E-commerce Dual-active Lessons – Sharding, Routing, Consistency
This article shares practical lessons from implementing unitized architecture for an e-commerce platform's cross-region dual-active deployment, covering sharding strategies, traffic routing, data classification, consistency trade-offs, hidden risks, and a decision checklist for when to adopt unitization.
Introduction: Core Misconception
The team launched a cross-region dual-active transformation before a major promotion. The initial aggressive plan aimed for full-link unitization across the transaction chain. Load testing immediately revealed hard-to-reproduce issues: inventory conflicts when two units deducted stock for the same item simultaneously; after failover drills, some existing orders were missing in the target unit; introducing distributed transactions to smooth cross-unit data differences cut throughput in half.
Many articles equate unitization with multi-active deployment or confuse it with sharding. This is a dangerous misconception. The core purpose of unitization is fault domain isolation , not merely deploying across multiple data centers. Sharding, routing, and data synchronization are all means to that end, not goals themselves. Teams that blindly adopt unitization often end up with double the clusters, double the ops burden, and double the reconciliation work, while rarely triggering a city-level fault — carrying heavy architectural debt for years.
1. Clarify Boundaries: Don't Mix Concepts
The first review gate is distinguishing three concepts:
Sharding : Solves capacity bottlenecks . Data is split by rules to distribute storage pressure. The fault domain remains the entire database cluster; if one shard fails, the corresponding business becomes unavailable. It does not inherently provide fault isolation or multi-active write capability.
Traditional Cross-region Disaster Recovery : Solves data safety. Primary writes, standby asynchronously replicates; standby is normally read-only. Failover requires manual switch with a write downtime window — not multi-active.
Unitization : Builds self-contained business units . Each unit owns independent gateway, applications, cache, and database cluster, capable of handling complete transaction business independently. Multiple units accept write traffic simultaneously, routed by sharding rules. A fault only affects users of the corresponding shard; other units operate normally.
Unitization is not a universal upgrade; it is a choice that sacrifices simplicity for a higher fault isolation ceiling .
2. E-commerce Unitization Implementation: Sharding and Traffic Routing Engineering Choices
The e-commerce platform adopted user ID hash sharding with dual peer-active units (same-city + cross-region active), the safest sharding strategy for transaction businesses. Sharding key selection is the first red line: sharding by product ID would concentrate flash-sale traffic on one unit; sharding by merchant ID would create a hotspot for top merchants. User ID sharding naturally binds to the user access path : a single user's ordering, order query, coupon deduction, and inventory deduction all land in the same unit, keeping the vast majority of reads and writes inside the unit and minimizing cross-unit calls.
The traffic routing layer is the control plane core. A two-layer routing design is used: the gateway layer pre-computes sharding based on user ID hash and routes to the target unit. Under normal conditions, routing rules are statically pushed for lowest latency; the control plane maintains routing metadata and dynamically adjusts shard mapping when a unit suffers data center failure or resource exhaustion, redirecting that unit's shard users to another healthy unit.
A frequent pitfall is user routing stickiness . User A originally lands in Unit A; after failover, traffic is scheduled to Unit B. If only new requests are routed, historical orders and data remain in Unit A. Without cross-unit fallback query logic, the user cannot see previous orders or refund records after cutover. Many teams only implement traffic switching and ignore historical data compatibility, exposing this issue only during drills.
Based on this constraint, routing specifications were defined:
Normal operation prioritizes intra-unit closed-loop; strictly prohibit normal cross-unit synchronous writes.
Routing changes are major ops actions; no millisecond-level auto-failover; add manual review thresholds.
After cutover, new writes go to the new unit; queries first check the current routing unit, then fall back to cross-unit query if not found.
3. Data Classification Governance: Cross-unit Consistency Trade-offs
The hardest part of unitization is not routing or sharding, but data. The platform classifies data into three categories, each with a fixed consistency strategy, enforced in review checklists:
Unit-private Data (ideal form) : User orders, coupons, assets, shopping carts. Ownership follows the sharded user; written only in the owning unit, other units do not participate. This achieves full unit closed-loop with no cross-unit conflicts; performance and consistency are controllable.
Global Read-only Base Data : Product base info, platform activity configs, dictionaries, categories. Read-only in all units; changed only in config center, then asynchronously broadcast to all unit caches and databases. Risk : sync latency. A product taken offline may be updated in Unit A while Unit B's cache still serves it, allowing orders briefly. Business must accept this short window or add strong validation fallback; unitization itself cannot eliminate this latency.
Cross-unit Writable Data (avoid unless unavoidable) : Shared product inventory is typical. Products don't belong to a single user; users from different shards across units deduct the same SKU inventory. This is the biggest pain point. The team rejected cross-unit 2PC strong consistency: under peak traffic, synchronous cross-unit lock waits would crush the chain. The final choice: a dedicated Global Inventory Center deployed independently from business transaction units; all units call the global inventory service for deductions, which handles its own deduction, locking, and idempotency.
Key insight: Don't force global resources into unit closed-loops. Forcing them in leads to endless data conflicts and reconciliation nightmares.
Any shared resource that cannot be assigned to a user shard should be extracted as a global service, not forced into the unit interior.
4. Hidden Risk Checklist: Post-launch Explosive Issues
These engineering costs rarely appear in design docs but are review focal points:
Sharding Skew Risk : Hash sharding isn't a silver bullet. Zombie users or batch-registered accounts can still cause uneven unit traffic; continuous shard heat monitoring and rebalancing support are needed. However, rebalancing is high-risk: during user data migration, read-write conflicts, duplicate orders, and order loss risks are extreme; must be done off-peak with throttling and dual-write fallback.
Async Sync Link Unreliability : Cross-unit async messages can be lost, duplicated, or reordered. Integrated with the previous local message table system, all cross-unit sync events carry a unique business serial; the receiver enforces idempotent validation.
Change Complexity Doubles : Version releases, database DDL, middleware config changes must be executed synchronously across all units. Version inconsistency between units causes interface compatibility issues. Canary scope and rollback order require extra design.
Reconciliation Cost Skyrockets : Two reconciliation systems — intra-unit + cross-unit global. Daily checks cover intra-unit orders, global inventory, cross-unit coupon consumption. Small teams lack ops bandwidth; this becomes a massive burden.
Drill Blind Spots : Many teams only drill full-unit failover, rarely half-failure scenarios: unit network partition, partial data sync channel interruption . These half-fault scenarios hide data inconsistency most insidiously, with extremely high post-mortem cost.
5. Decision Red Lines: Businesses That Must Not Unitize (Core P7 Judgment)
Unitization is not the standard answer for high availability; avoid it if possible.
✅ Suitable scenarios : Core transaction links, massive traffic fluctuations during promotions, need to withstand data center/city-level faults, business can tolerate brief global data inconsistency, team has ample ops, reconciliation, and drill manpower.
❌ Do not force unitization : Stable business volume with low traffic; business links contain many inseparable shared writable resources; business requires strong consistency and cannot tolerate any data deviation; dev/ops headcount is tight with no stable drill mechanism.
Many architects treat unitization as a resume highlight when the business scale cannot support the complexity. The result is architectural overcapacity, drastically reduced daily iteration efficiency — classic over-engineering. Architecture's value is matching business risk, not stacking advanced solutions.
6. Unitization Architecture Implementation Review Checklist (Ready to Reuse)
Transformation goal: Is the fault domain to isolate a data center failure or a city-level failure? Is there a lower-cost solution (multi-AZ, primary-standby DR) that suffices?
Does the sharding key match the core access path, enabling the vast majority of reads/writes to stay intra-unit?
Are there high-frequency shared writable resources that cannot be sharded? Is there a dedicated global handling plan?
Are cross-unit data consistency levels and tolerable latency confirmed with product and business?
Are shard skew, rebalancing plan, and data migration contingency ready?
Are routing switch, cutover, rollback, and historical data fallback query implemented?
Are cross-unit sync idempotency, retry, and dead-letter fallback complete?
Are reconciliation system, monitoring dashboards, and drill plans in place?
Are long-term resource and ops costs acknowledged by business?
Conclusion
The essence of unitized architecture is isolating faults, not perfecting consistency . It trades multiples of system complexity, resource cost, and ops burden for one capability: a single large-scale fault will not wipe out the entire business. A mature architect is not one who can skillfully build a cross-region multi-active unitization, but one who calmly judges at the review stage: does the current business risk justify paying this price?
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
