High-Concurrency Event Reservation System: Technical Practices
This article breaks down the technical foundations of a high-concurrency event reservation platform built around reservation, daily login accumulation, task tokens, and prize redemption. It covers a layered architecture, a time-window state machine, two-phase node unlocking, idempotent token ledgers, lottery and stock deduction, rate limiting and degradation, observability and reconciliation, plus common pitfalls to avoid.
1. Abstracting the Scenario into Technical Problems
The source material describes a common set of operational mechanics: event reservation, login accumulation, task tokens, and lottery redemption. Setting aside the operational packaging, the technical core reduces to four general problems:
- A state machine driven by time windows: Every event has a start time, an end time, and intermediate milestones. The system must open entry points and unlock rewards at the right moments.
- High-concurrency reads and writes: A concentrated traffic spike appears the instant an event opens. Reservation, login, and reward claiming are all writes, and they carry obvious hotspots.
- Idempotency and consistency: Repeated clicks by the same user, network retries, and duplicate message delivery must never cause duplicate reward issuance.
- Configurability: Event rules, prize pool contents, and milestone times need to be self-service configurable by the operations side, rather than requiring a release for every change.
Once these four points are clear, the architecture design that follows has a consistent standard for evaluation.
2. Layered Architecture
A reusable event support platform is typically divided into five layers:
- Access layer: Provides a unified traffic entry point, protocol conversion, rate limiting, and front-loaded risk control.
- Event orchestration layer: Models four entity types—event, phase, task, and reward—to drive state transitions.
- Capability layer: Reservation registration, login check-in, task counting, token accounts, lottery, redemption, and mail delivery.
- Data layer: Relational storage holds configuration and accounts, cache handles hot reads and writes, and a message queue provides asynchronous peak shaving.
- Observability layer: Metrics, logs, distributed tracing, and alerting.
A schematic domain model can be written as the following pseudocode:
Activity {id, name, startTime, endTimeList<Node> nodes // key time milestonesList<Task> tasks // login/task/shareList<RewardPool> pools // prize pools and redemption area}Node {id, unlockTime, rewardRef}UserActivityState {userId, activityIdloginDays, tokenBalancenodeSubscribeSetreceivedRewardSet}
The key point is that the uniqueness of reward issuance is guaranteed by receivedRewardSet together with the order number, not by relying on the frontend not clicking twice.
3. Reliable Reservation and Milestone Unlocking
Reservation is essentially “writing a subscription record,” and milestone unlocking is essentially “batch-generating pending-issuance records when the time arrives.” The recommended engineering approach is two-phase:
- When a user reserves, only write the subscription record and return an accepted response; do not issue rewards directly.
- A scheduled job triggers at each milestone time, scans the subscription set, generates issuance tasks, and posts them to a message queue, where consumers execute them idempotently.
This avoids the database being overwhelmed the instant a milestone hits, and it makes failures replayable. Scheduling needs to account for clock consistency: use server time uniformly, and apply distributed mutual exclusion across scheduler instances to prevent duplicate scans by multiple instances.
onNodeUnlock(nodeId):lock(nodeId) // distributed lock to avoid duplicate scansusers = subscribeStore.list(nodeId)for u in users:mq.send(RewardTask{u, nodeId, dedupKey=u+nodeId})
dedupKey is the core of idempotency; consumers use it to enforce a unique constraint when persisting.
4. Idempotent Design for Login Accumulation and Token Accounts
The difficulty in cumulative-login mechanics lies in “day boundaries” and “make-up sign-in / delayed participation.” Recommended practices:
- Aggregate by natural day, and record
lastLoginDateandcontinuousDayson the server; client time is untrustworthy. - Store accumulated days with a bitmap or integer bitwise operations. Checking “whether day N has been checked in” requires only a single bit check, which is both space-efficient and fast.
- Use a dual-table design of “ledger + balance” for the token account. The ledger table uses a unique index to prevent duplicates, and the balance is updated via a transaction or optimistic locking.
CREATE TABLE token_ledger (id BIGINT PRIMARY KEY,user_id BIGINT NOT NULL,activity_id BIGINT NOT NULL,biz_key VARCHAR(64) NOT NULL,delta INT NOT NULL,UNIQUE KEY uk_biz (activity_id, user_id, biz_key));
5. Lottery and Redemption: Probability, Stock, and Anti-Abuse
Lottery should separate two phases: “random result generation” and “prize deduction.” The recommended approach is to first compute the winning result on the server according to configured weights, then attempt to deduct prize stock; if deduction fails, fall back to a guaranteed consolation prize, avoiding the situation where a user sees “won but not received.” Stock deduction should use a conditional atomic update:
UPDATE prize_stock SET remain = remain - 1WHERE pool_id = ? AND prize_id = ? AND remain > 0;
An affected row count of 0 means sold out, and the fallback logic must run. The redemption store works the same way: use “user points/tokens >= price” as the update condition to guarantee that a negative balance never occurs. For anti-abuse, apply rate limiting at the access layer, plus device- and account-level risk control, and return a unified error code for abnormally high-frequency requests rather than dropping the connection outright.
6. Stability: Rate Limiting, Peak Shaving, and Degradation
The characteristic of an event traffic peak is “extremely high instantaneous concurrency over a short duration.” Available strategies include:
- Access-layer rate limiting: Multi-level token buckets by API, by user, and by source to protect the backend.
- Asynchronous processing: Reservation, reward claiming, and mail delivery all go through a message queue, and the frontend receives an “accepted” response.
- Hotspot caching: Two-level caching of event configuration and prize pool metadata—local cache plus distributed cache—with configuration changes invalidated by version number.
- Degradation plans: Non-core display APIs can degrade to static fallback data, while the core reward-issuance path is prioritized.
It must be emphasized that no degradation may break idempotency; otherwise duplicate issuance will occur after recovery.
7. Observability and Operational Support
After an event goes live, the biggest fear is “not knowing whether rewards were issued, or to whom.” At least three capabilities are recommended:
- Metrics: Reservation volume, milestone unlock success rate, reward issuance success rate, message backlog, and API P99 latency.
- Logs and tracing: Use
activityId + userId + bizKeyas the fields threaded throughout, to make troubleshooting easier. - Reconciliation jobs: Periodically compare “records that should be issued” against “records actually issued,” output the differences, and compensate automatically.
If relying on general cloud capabilities, a container platform can host stateless services, a message queue can shave peaks, object storage can archive event data, and log and monitoring services can close the observability loop. These are all industry-standard categories, not tied to a specific implementation.
8. Common Pitfalls
- Putting time checks on the client, so changing the device clock allows early claiming.
- Using database auto-increment or pure in-memory counters for reward-issuance uniqueness, which fails after a restart or scale-out.
- Deducting stock before computing probability in the lottery, causing high-value prizes to be occupied in vain.
- Hard-coding event configuration, so every adjustment requires a release, making operations extremely inefficient.
9. Summary
Event reservation and login-reward requirements look simple, but delivering them in practice comes down to four things: the time state machine, idempotent reward issuance, hotspot peak shaving, and observable reconciliation. Abstract the domain model clearly, push uniqueness constraints down to the storage layer, and make non-core paths asynchronous—this supports high-concurrency operational events at relatively low cost and lays the groundwork for reusing the mechanics in future events.
