跪拜 Guibai
← All articles
Backend

Spring Boot 3 + Vue 3 Course Selection System Replaces First-Come with Public-Seed Lottery

By 黃芢輝 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

This is a concrete reference implementation for fair, auditable seat or resource allocation without concurrency contention, useful for any system that must be both equitable and explainable. The public-seed recomputation design carries real trust value in educational settings and beyond.

Summary

The project, by 黃芢輝, implements a full registrar-grade elective course management system. Students submit wishes with an order and points budget during a filling window; after the deadline, a batch lottery allocates seats in memory without concurrency locks, then writes results transactionally. The draw seed is public, and input snapshots are gzip+SHA-256 hashed, so third parties can recompute outcomes. Per-wish results record hit/miss reasons and placement order, giving students a clear audit trail.

The backend runs Java 21 with Spring Boot 3.3.5, MyBatis-Plus, MySQL 8, and Redis 7 (used only for token whitelist, draw lock, and heat snapshot — not for seat counts). The frontend is Vue 3.5 with Element Plus, Pinia, and ECharts. The admin console provides a draw phase machine, batch reports, grade entry with per-student corrections and audit logs, plus a 22-table schema. It includes a Docker Compose one-click startup and a native WeChat mini-program that reuses the same APIs.

Two branches exist: `master` uses Redis+Lua for real-time rush, while `feature/wish-lottery-selection` (the one described) favors fairness and reproducibility. The author explicitly avoids caching seat numbers, reruns are idempotent (old batches marked SUPERSEDED), and submission time never influences weighting.

Takeaways
— The draw uses HMAC-SHA256(seed, studentId) as the final tiebreaker in a MIXED weight strategy (points → earned credits → HMAC).
— Seat remaining counts are computed from the database only, never Redis, to avoid cache/DB drift.
— R1 results allow drops until a deadline; R2 results are final and lock drops (error 3013).
— Reruns are idempotent: before rerunning, the current round's selections are reset to 'dropped' and the old batch is marked SUPERSEDED, preserving history.
— Time conflict detection requires four conditions: same day, overlapping periods, overlapping weeks, and compatible week type (every/odd/even).
— Each student can submit up to 8 wishes with a total of 100 points per round.
— Grades are computed as 30% usual + 70% final exam, with GPA on a 4.0 scale.
— Redis keys include a global switch, token whitelist, draw single-writer lock (10 min), and heat snapshot (2 hours).
— The database has 22 tables; course_selection has a unique key on (student_id, course_id, semester_id).
— Demo accounts use {noop} plaintext password 123456; production must override JWT_SECRET and change all default passwords.
Conclusions

By making the seed public and snapshots gzip+SHA-256, the system turns a lottery into a verifiable computation, which is a strong trust signal in an academic environment where fairness is paramount.

Keeping seat counts solely in the database sidesteps the classic cache-coherency nightmares of flash-sale style systems, at the cost of a draw that is inherently batch-based rather than real-time.

The soft constraint that only warns on timetable conflicts between wishes preserves the 'A misses, fall to B' logic, a design choice that prevents over-constraining a fair lottery.

The explicit split into two branches lets developers compare real-time rush and lottery approaches in the same codebase, which is a rare educational opportunity.

Concepts & terms
Wish + Lottery Selection
A course allocation mechanism where students rank courses (wishes) and optionally allocate points during a submission window; after the deadline, a batch algorithm assigns seats uniformly, independent of submission time.
HMAC-SHA256 weighting
A deterministic pseudo-random tiebreaker computed from a public seed and student ID, allowing the draw order to be reproducible by third parties while preventing manipulation.
Batch snapshot
A compressed (gzip) and hashed (SHA-256) snapshot of the lottery input (courses, students, wishes) stored per batch, enabling independent recomputation of draw results.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗