In competitive Bangladeshi academic and government job preparation, instant feedback is paramount. When 25,000 candidates finish a timed Primary or BCS model test on Sohoj Pathshala (sohojpathshala.com), waiting hours for merit rankings causes anxiety and support ticket overload. Here is the technical breakdown of how SOFT IT engineered a sub-100ms grading and leaderboard engine using Laravel 10 and Redis Sorted Sets.
1. Mathematical Challenges in Automated Negative Marking
Standard multiple-choice tests simply calculate \(Score = Correct \times Marks\). However, competitive exams mandate negative marking to penalize random guessing:
Tie-Breaking Criteria: Exact Submission Milliseconds + Subject Priority
When two candidates obtain the identical net score (e.g. 78.75), tie-breaking must evaluate exact submission timestamps down to milliseconds, followed by accuracy ratios in core subjects (e.g., Bengali, Mathematics, and General Knowledge). Performing this evaluation on traditional SQL tables with window functions (`DENSE_RANK() OVER (...)`) across 30,000 rows consumes massive database CPU resources and locks tables for seconds.
2. The Redis Sorted Set (ZSET) Architecture
To eliminate SQL computation overhead, SOFT IT implemented Redis Sorted Sets for national leaderboard ranking:
- Score Encoding: A composite floating-point score is generated that encapsulates both the test score and fractional submission latency. For instance, a score of 82.50 achieved at \(T\) seconds after start time is encoded as a precise 64-bit float.
- Instant Rank Retrieval: Using Redis `ZREVRANK exam:104:leaderboard user:9842`, the candidate's exact national position (e.g., Rank #42 out of 28,450) is returned in less than 2 milliseconds.
- Percentile Distribution: Redis `ZCOUNT` queries calculate instantaneous percentiles (e.g., "You scored higher than 94.6% of examinees nationwide"), delivering rich psychological reinforcement to candidates.
3. Resilience Against Client-Side Tampering
Online exams are prone to client-side timing attacks where users manipulate their local operating system clock to gain extra time. Sohoj Pathshala's exam engine implements three layers of security:
- Server-Driven Ephemeral Tokens: Upon test launch, an encrypted JWT with cryptographically signed server timestamps is issued.
- Heartbeat Synchronization: A lightweight WebSocket ping verifies exam status every 30 seconds.
- Strict Server-Side Deadline Enforcement: Submissions received more than 5 seconds after server deadline are automatically marked as timed-out submissions.
Through this architecture, Sohoj Pathshala delivers transparent, tamper-proof, and lightning-fast examination grading that candidates and instructors trust implicitly.