How louisyi-n/miaosha works
Project type and purpose
• This is a full-stack, high-concurrency “秒杀”(flash sale) system built with Spring Boot, Dubbo/RPC, Redis, RabbitMQ, MySQL and Zookeeper.
• It consists of multiple Maven sub-modules: core seckill app (miaosha-2version), admin portal (miaosha-admin), order microservice (miaosha-order), demo SpringBoot + Dubbo examples (springboot-dubbo), plus common libraries.
Top-level components
a. Clients
– Web browser/mobile app (静态页面 + AJAX calls)
– Admin UI
b. Edge/proxy
– Nginx (static caching, load balancing)
c. API/Web Tier
– miaosha-web (Spring Boot controllers, interceptors, templates, static resources)
– miaosha-admin-web (Freemarker, JSP)
d. Service Tier
– miaosha-service (business logic: GoodsService, MiaoshaService, OrderService)
– miaosha-admin-service (admin APIs)
– miaosha-order-provider (order microservice via Dubbo)
– springboot-dubbo/provider & consumer demos
e. RPC framework
– Dubbo clients & providers, Zookeeper for service registry
f. Messaging
– RabbitMQ (MQSender → MQReceiver for order queue)
g. Cache & Locking
– Redis cluster (stock pre-decrement, distributed locks via Lua/redisson)
h. Persistence
– MySQL master-slave cluster
i. Infrastructure & config
– Zookeeper ensemble, monitoring/logs (optional)
Relationships & interactions
1. Client → HTTP → Nginx (LB/static) → Spring Boot web app
2. Web app →
• Redis (GET initial stock, check sold-out flag)
• Local in-memory flags
• If allowed, push message to RabbitMQ queue
3. MQReceiver (in service tier) →
• Consume seckill request → RPC (Dubbo) if order service is remote → Business logic →
• Persist order to MySQL → Cache update
4. Web app polls or returns async result (via Redis or database)
5. Admin UI → Dubbo/Admin service → MySQL/Redis
Architectural patterns & principles
• Layered architecture: controller → service → dao → database
• Asynchronous processing with message queue for smoothing spikes
• Cache-aside & pre-decrement pattern in Redis for inventory
• Distributed locking via Redis/Lua scripts or Redisson
• RPC microservices via Dubbo + Zookeeper
• Master-slave MySQL for read/write separation
• Externalized configuration via Spring profiles, properties, XML for Dubbo
Guidance
– RPC (dot-dash) between service modules via Dubbo/ZK
– UI/Client (blue)
– Web/API (green)
– Business Service (yellow)
– Infrastructure (gray)
• Flows: e.g., “1. 浏览器请求商品列表”, “2. Redis 库存检查”, “3. MQ 下单消息”, “4. 消费并生成订单”.
Detailed elements
• Nginx/Load balancer → multiple instances of miaosha-web & miaosha-admin-web
• Dubbo consumers in web/app modules → Dubbo providers in service modules
• RabbitMQ cluster between Web and Service
• Redis cluster for cache, lock, sold-out flag
• MySQL master for writes, slaves for reads
• Zookeeper ensemble for service registry
• Local memory map in Web app (sold-out flags for fast-fail)
• Key configuration files (application-*.properties, Dubbo XML) can be footnoted