Design CoderPad (live collaboration, replay features, etc.)
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2022-06-09
Problem Statement
Interview platforms like CoderPad or CodePair allow candidates and interviewers to collaborate in real-time. The system should support live code collaboration, execution, replaying past sessions, and persistence of interview data — all with low latency and scalability.
✅ Functional Requirements
1.Real-time Collaboration
•Multiple users (interviewer + candidate) edit the same coding pad.
•Changes must propagate instantly (<200ms).
•Cursor positions and highlights should be visible to all users.
2.Code Execution
•Users can execute code in multiple programming languages (Java, Python, C++, etc.).
•Must provide secure sandboxes to run untrusted code.
•Capture stdout, stderr, exit code.
3.Session Replay
•Record all keystrokes, edits, and executions during a session.
•Allow playback later in "replay mode".
4.Persistence & Sharing
•Save pad state for later access.
•Generate sharable links (with configurable expiration).
5.Interview Features
•Whiteboard mode for diagrams.
•Chat/messaging within the session.
•Optional video/audio integration.
❌ Non-Functional Requirements
•Low Latency: Edits should propagate in <200ms.
•Scalability: Handle thousands of concurrent sessions.
•Reliability: No loss of edits, even with network glitches.
•Security: Code execution must be sandboxed to prevent host compromise.
•Replay Efficiency: Session replay should be efficient and not bloat storage.
🧱 System Components
1.Collaboration Engine
•Operational Transform (OT) or CRDT (Conflict-free Replicated Data Type) for handling concurrent edits.
•Real-time sync using WebSockets.
2.Code Execution Service
•Isolated container-based execution (Docker, Firecracker).
•Language runtime images (Python, Java, JS, etc.).
•Resource limits (CPU, memory, timeouts).
3.Replay Service
•Event log storage (insert, delete, cursor move, code run).
•Timestamped logs for accurate playback.
•Efficient compression to save space.
4.Storage Layer
•Metadata DB: Sessions, users, interview links.
•Blob Store: Replay logs, code files.
•Cache: Active pad states for fast recovery.
5.API Gateway
•Authentication, authorization.
•REST/GraphQL APIs for session lifecycle.
6.Monitoring & Analytics
•Track usage per session (edits/sec, executions).
•Detect abuse (infinite loops, malicious code).
🔄 Example Flow
1.Candidate & interviewer open a shared pad → WebSocket connection established.
2.Candidate types code → Collaboration Engine applies OT/CRDT → Broadcasts change.
3.Interviewer sees update in <200ms.
4.Candidate clicks "Run" → Code Execution Service spawns sandbox → Returns output.
5.Replay Service logs all keystrokes & executions → Stored in event log.
6.After session, recruiter replays full interview timeline.
⚖️ Trade-offs & Design Considerations
•CRDT vs OT: CRDTs handle offline merges better but are heavier; OT simpler but needs centralized conflict resolution.
•Replay Storage: Store deltas vs full snapshots (trade-off: replay accuracy vs storage size).
•Sandbox Security: How to isolate code execution (VM vs container vs serverless).
•Multi-tenancy: Ensure one company’s interview doesn’t affect another’s performance.
•Video/Audio: Should be integrated or delegated to third-party (Zoom, WebRTC)?
🧪 Open Discussion Points
•How to scale real-time editing to thousands of concurrent pads?
•Should code execution be queued or parallelized per user?
•How to handle offline edits if a client temporarily disconnects?
•Replay efficiency: store keystroke logs vs timed snapshots + diffs?
👉 This problem tests real-time collaboration (CRDT/OT), sandboxing, storage design, and event replay — great for senior-level system design interviews.