Full answer
Requirements
Functional:
- Browse courses, enrol, watch video lessons, resume where you stopped.
- Take quizzes (multiple choice and short answer), some timed; see scores.
- Instructors upload videos and create quizzes; learners see a progress bar and certificates.
Non-functional:
- Videos start quickly and adapt to slow mobile networks.
- Quiz answers are never lost, even at the deadline rush.
- Correct answers are not exposed to the browser before submission.
Capacity estimates
Assumptions: 2M daily learners, 200,000 concurrent video viewers at peak, 1.5 Mbps average bitrate, a timed test where 50,000 students submit in the final minute.
- Video egress: 200,000 x 1.5 Mbps = 300 Gbps at peak, served by a CDN.
- Quiz rush: 50,000 / 60 = about 830 submissions per second.
- Progress events: if each viewer sends one heartbeat every 30 seconds, 200,000 / 30 = about 6,700 per second, which is why they are batched.
API
GET /v1/courses/{id} -> outline with lessons and the learner's progress
GET /v1/lessons/{id}/playback -> {"manifest_url": "https://cdn.../master.m3u8?token=..."}
POST /v1/progress {"lesson_id", "position_s": 312, "completed": false} (batched by the client)
POST /v1/quizzes/{id}/attempts -> {"attempt_id", "questions": [...without answers], "ends_at"}
PUT /v1/attempts/{id}/answers {"q1": "B", "q2": "C"} (autosave)
POST /v1/attempts/{id}/submit -> {"score": 8, "max": 10}
Data model
courses,lessons(video asset ID, duration),enrolments(user_id, course_id, status).lesson_progress: (user_id, lesson_id) to position, completed, updated_at.quiz_questions: question_id, quiz_id, body, options, correct_answer (never sent to clients).attempts: attempt_id, user_id, quiz_id, started_at, ends_at, answers (JSON), score, submitted_at.
High-level design
mermaid
flowchart LR
L[Learner] --> CDN[CDN: pages and video segments]
L --> API[Learning API]
API --> DB[(Courses, progress, attempts)]
API --> Q[(Progress event queue)]
Q --> W[Progress workers] --> DB
I[Instructor] --> UP[Upload service] --> OS[(Object storage)]
OS --> TC[Transcoder] --> OS
OS --> CDNKey flows
- Video. Instructor uploads go to object storage; a transcoder creates 240p to 1080p HLS renditions; the player requests a signed manifest so only enrolled learners can watch.
- Progress. The player sends heartbeats, batched every 30 seconds; workers upsert
lesson_progress. Losing one heartbeat only loses a few seconds of position. - Quizzes. Answers autosave during the attempt. The server enforces
ends_at(with a small grace period) and grades on submit using the stored correct answers. A submission is idempotent per attempt, so a retry after a network error does not create a second attempt.
Bottlenecks and trade-offs
- Deadline rush. Autosave spreads writes across the test, so the final submit is a small update; the queue can absorb grading if it is heavier (for example code questions).
- Video cost. Most cost is CDN bandwidth; offer lower default quality on mobile data and download for offline viewing.
- Cheating in timed tests. Randomise question order and options, draw from question pools, and keep answers server-side.
- Monolith first. At this scale a well-structured monolith with a relational database, a CDN and a transcoding service is enough; split services only when teams or load require it.
By level
Fresher: Describe courses, lessons, progress and quiz tables, and explain that videos come from a CDN. A fresher should know why correct answers stay on the server.
Mid: Do the bandwidth and rush math, batch progress events, design autosave and idempotent submission, and sign video URLs. Mention transcoding.
Senior: Discuss cost control for video, cheating defences, coding sandboxes, certificates, and when to split the monolith. Expect a design sized to the real load.
Key points
- CDN for pages and pre-transcoded video
- Relational database for courses, enrolments, progress and attempts
- Batch progress heartbeats
- Autosave answers and grade on the server; never send correct answers
- Idempotent quiz submission per attempt
Common mistakes
- Sending correct answers to the browser
- Writing a database row for every second of video watched
- Accepting submissions after the deadline without server-side checks
- Streaming video from the application servers
Follow-ups
- How would you add coding exercises that run in a sandbox?
- How would you issue verifiable certificates?
- How do you support offline viewing on phones?
Tips
- Identify video bandwidth and deadline rush as the two load points
- Explain autosave
- Keep the architecture simple for the scale
Evaluation rubric
- Correct video delivery design
- Capacity math for video, progress and quizzes
- Secure, idempotent quiz handling
- Sensible simplicity and trade-offs