Design a test-taking website/service
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-02-18
Problem Statement
Design and implement a test-taking platform where users can attempt quizzes/exams online. The system should manage users, questions, tests, submissions, scoring, and result generation with proper validation and extensibility.
Functional Requirements (FR)
User Management
•Users can register/login.
•Roles: Admin/Instructor (creates tests), Student (attempts tests).
•Profile management (name, email, history of tests taken).
Test & Question Management
•Instructors can create/edit/delete tests.
•A test contains metadata (title, duration, start/end time, passing score).
•Question types supported:
•Multiple Choice (single/multiple correct)
•True/False
•Short Answer
•Coding/Programming (optional extension)
•Questions can have marks and negative marking.
Test Attempt & Submission
•Students can start an available test.
•Timer starts when test begins; auto-submit on timeout.
•Answer validation (cannot submit multiple times).
•Support save and continue.
•Prevent cheating (optional: randomize questions, time limit per question, IP restrictions).
Scoring & Results
•Auto-calculate scores based on answers.
•Handle partial credit (for multi-select MCQs).
•Show detailed report: attempted questions, correct answers, score, pass/fail.
•Instructors can view results of all students.
Notifications
•Notify users about test availability.
•Reminders for upcoming deadlines.
Non-Functional Requirements (NFR)
•Scalability → Support thousands of concurrent test-takers.
•Reliability → Ensure test progress is not lost on refresh or disconnection.
•Low Latency → Submissions and scoring should be near real-time.
•Security → Prevent tampering, protect question bank, encrypt sensitive data.
•Extensibility → Support coding challenges or adaptive tests in future.
Core Entities & Attributes
User
•userId, name, email, role (Student/Instructor), testHistory
Test
•testId, title, description, duration, startTime, endTime, passingScore, questions
Question
•questionId, text, type, options[], correctAnswer(s), marks, negativeMarks
Submission
•submissionId, testId, userId, answers[], startTime, endTime, score, status
Result
•resultId, submissionId, userId, totalScore, passed, detailedBreakdown
APIs / Operations
User APIs
•registerUser(name, email, role)
•login(email, password)
Test APIs
•createTest(instructorId, testDetails)
•addQuestion(testId, questionDetails)
•getAvailableTests(userId)
Attempt APIs
•startTest(userId, testId)
•submitAnswer(userId, testId, questionId, answer)
•submitTest(userId, testId)
•getSubmission(userId, testId)
Result APIs
•calculateResult(submissionId)
•getResult(userId, testId)
•getAllResults(testId)
LLD Design Goals
•Class Diagram → Entities: User, Test, Question, Submission, Result, TestManager, ScoringService.
•Design Patterns:
•Strategy Pattern → for scoring different question types (MCQ, coding, true/false).
•Observer Pattern → for notifications/reminders.
•Factory Pattern → for creating questions of different types.
•Handle trade-offs:
•Where to store submissions (in-memory vs DB).
•Auto-scoring vs. manual scoring (e.g., for subjective questions).
•Cheat prevention vs. user experience.