Design a nested comments and threads API
PremiumAPI designEasy
- Threaded comments
- Tree pagination
- Cursor pagination
Quick answer
This API design interview question asks you to design a nested comments and threads API. Aim for a design that exposes a clear, consistent and safe interface, then explain the resources, requests, responses and error handling. Interviewers want to see how you name resources, version the interface and handle failure cases.
The problem
Design a nested comments and threads API like Reddit's for a news site: readers comment on an article or reply to any comment, with no fixed depth limit. The hard parts are loading a huge tree fast in pages, expanding deep branches on demand and deleting a comment without breaking its replies.
Popular articles reach 20,000 comments with branches 40 levels deep. Design the HTTP API that the web and mobile clients will call.
What must a nested comments and threads API do?
- Read a thread: Load the first page of top-level comments with a few levels of replies already included, sorted by best, newest or oldest.
- Create: Post a comment on an article or as a reply to a comment, 1 to 5,000 characters, plain text with limited markdown.
How well must it do it?
- Latency: First page of a thread under 150 ms at p95 for an article with 20,000 comments.
- Bounded responses: No response contains more than 200 comments or more than 5 levels, whatever the thread shape.
What scale should you design for?
Use these numbers in your estimates.
The scale numbers unlock with this questionUnlock
Key concepts
- Threaded comments
- Tree pagination
- Cursor pagination
- Soft delete
- Permalinks
- Moderation
How you’ll practise
- Use cases
- Resources
- Endpoints
- Errors, auth and limits
- Versioning
- Wrap-up
Lala, personalized to you, gives a hint when you ask and reviews your design when you are ready.
What do interviewers look for?
In any API design round.
- Starts from the clients and the use cases
- Names resources and operations consistently
- Defines request and response shapes and status codes
- Covers authentication, rate limits and idempotency
- Plans pagination, filtering and versioning
- Explains how clients learn about and recover from errors
Questions people ask about this interview question
- Which design type is this question?
- It is an API design question. You design a nested comments and threads API and explain your choices the way you would in an interview.
- Is this question asked at entry level?
- It is marked Easy, so it suits engineers who are new to API design interviews. It is also a good warm-up before harder questions.
- What should I cover first?
- Start with the clients, the main use cases and the resources they need. Agree on scope with the interviewer before you design anything.
- Can I practise it for free?
- It is a premium question. Sign up and unlock it once for 10 credits; it then stays unlocked. When you finish, Lala, your personalized AI mentor, can review your design for 30 credits.
Related questions
Updated · Written by the SevyDevy team