List functional requirements for the system (Ask interviewer if stuck)...
Estimate the scale of the system you are going to design...
Assume that there are 10,000 DAU, each user has 500 tags on average. So there are 500*10,000 = 5,000,000 tags in total
Assume that each user add 5 tags per day, then there are 50,000 tags added per day
if 20% of the datas added per day are updated, then 50,000 * 20% = 10,000 updates per day;
Assume each tag is 80 bytes, then we need at least 5,000,000 * 80 bytes = 0.4 Gb
Define what APIs are expected from the system...
RESTful APIs:
@Create
void create(String tagName)
@Batch_Create
void batchCreate(List
@Update
void update(Tag tag)
@Delete
void delete(Tag tag)
@Get
List
List
List
List
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
Data model:
Tag {
id: int (autoincrement),
name: varchar,
metadata: varchar
}
TagCategory {
id: int,
name: varchar,
}
TagToCategoryMapping {
tagId: int,
categoryId: int
}
Choice of Database:
You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design...
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
- How to efficiently store and retrieve tags in db? (database schema design)
We store the tags in the relational database.
Indexing:
Data Storage mechanism:
- How to implement tag suggestions?
Using typeahead search.
Create a table to store popular or trending tags for generating suggestions:
tagFrequency {
id: int -> primary key,
tagName: varchar,
frequency: int
}
We need a tagSuggestionService to do the recommendation.
Explain any trade offs you have made and why you made certain tech choices...
Trade-offs:
Tech Choices:
Could leverage message broker such as Kafka to do the real-time updates for tag suggestions
Try to discuss as many failure scenarios/bottlenecks as possible.
SOP(single point of failure): do data replications. use master-slave servers
Utilize in-memory data stores like Redis for caching frequently accessed tags and metadata. Implement indexing on tag fields to speed up search operations. Utilize search technologies like Elasticsearch for efficient full-text search capabilities. Employ sharding techniques to distribute data across multiple nodes and balance the load effectively.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?