E-Commerce System Design and Architecture (电子商务系统设计与体系结构)
Domain 3 asks you to turn requirements into an architecture: layers, deployment topology, decomposition, and the mechanisms that keep a busy shop alive during a promotion. Answers are judged on whether each design choice is justified by a quality attribute.
Layering and deployment
Classic three layers: 表现层 / 应用逻辑层 / 数据层, with B/S preferred for reach and C/S for rich local processing. Multi-tier adds web servers, application servers (middleware), and database servers behind 负载均衡, often with CDN and reverse proxy for static content. Session state must be addressed explicitly: sticky sessions, a shared session store, or stateless tokens.
Decomposition and interfaces
SOA exposes coarse business services over an enterprise service bus; microservices split by business capability with independent deployment. Interfaces are usually RESTful: resources, HTTP verbs, status codes, versioning, idempotency keys for payment and order creation. Design for high cohesion and low coupling; business logic belongs in the service layer, not in the browser or in stored procedures.
Quality attributes
- Availability: redundancy, clustering, dual-site, health checks, graceful degradation.
- Scalability: horizontal scaling, stateless services, sharding, caching.
- Performance: page staticisation, CDN, Redis cache, message queue for peak shaving, rate limiting.
Worked example
A 秒杀 (flash sale) with 100,000 concurrent users and 1,000 units of stock. Reasoning: static product pages to CDN so reads never touch the database; preload stock into Redis and deduct atomically with a Lua script to avoid oversell; put successful deductions onto a message queue and create orders asynchronously; add a gateway rate limiter and a queue token so only a fraction reaches the service. Each mechanism maps to one attribute: CDN to performance, Lua atomic deduction to consistency, MQ to peak shaving, limiter to availability.
Traps that cost marks
- Equating high availability with nightly backups.
- Assuming microservices always beat a monolith, ignoring operational cost.
- Forgetting session consistency after adding a second web node.
- Overselling because stock was read from the database without a lock or atomic decrement.