Kế hoạch: Prize Allocation Feature
1. Hiện trạng
- 9 dedicated queues với 9 listeners, mỗi queue serve một domain.
SendPrizeAllocationMessageService là single routing point.
PrizeAllocationHelperService xác định allocationType từ prize metadata.
- Concurrency:
1-1 cho critical queues (PRIZE, PRIZE_FOR_STREAMER), high cho UNLIMITED.
2. Vấn đề đã biết
| # |
Vấn đề |
Mức độ |
| 1 |
Không có idempotency key |
High - risk double allocation khi redelivery |
| 2 |
DLQ strategy không rõ ràng |
Medium |
| 3 |
Queue prefix config phân tán |
Low |
3. Kế hoạch cải tiến
Phase 1: Idempotency
- Task 1-1: Thêm idempotency key (UUID/correlationId) vào
PrizeAllocationData
- Task 1-2: Listener check idempotency key trước khi process (Redis TTL cache)
Phase 2: DLQ & Error handling
- Task 2-1: Xác định và document DLQ policy cho từng queue type
- Task 2-2: Review
JMSHandleDlqMessage và bổ sung monitoring/alerting
Phase 3: Observability
- Task 3-1: Metrics per queue: processing time, success rate, redelivery count
- Task 3-2: Alert khi queue lag vượt ngưỡng critical
Phase 4: Testing
- Task 4-1: Test toàn bộ actionType cho PRIZE queue
- Task 4-2: Test rollback (DECREASE) cho từng allocation type
- Task 4-3: Test MINT_ALLOCATION cho Hunter/Gauntlet/BountyBall
4. Timeline
gantt
title Prize Allocation - Improvement Plan
dateFormat YYYY-MM-DD
section Phase 1 Idempotency
Task 1-1 Idempotency key :crit, t1_1, 2025-01-01, 2d
Task 1-2 Listener check :crit, t1_2, after t1_1, 2d
section Phase 2 DLQ
Task 2-1 DLQ policy :t2_1, after t1_2, 2d
Task 2-2 DLQ monitoring :t2_2, after t2_1, 1d
section Phase 3 Observability
Task 3-1 Queue metrics :t3_1, after t1_2, 2d
Task 3-2 Alerts :t3_2, after t3_1, 1d
section Phase 4 Testing
Task 4-1 PRIZE queue test :t4_1, after t1_2, 3d
Task 4-2 Rollback test :t4_2, after t4_1, 2d
Task 4-3 Mint alloc test :t4_3, after t4_2, 2d
5. Rủi ro
| Rủi ro |
Ảnh hưởng |
Biện pháp |
| Double allocation khi redelivery |
Người chơi được nhận 2 lần |
Idempotency key (Task 1-1, 1-2) |
| Wrong queue routing |
Sai business outcome |
Unit test routing logic |
| UNLIMITED queue overload |
Throttle gameplay |
Monitor + scale consumer count |
| Backlog PRIZE queue |
Tạo room chậm |
Tune concurrency + alert |