System design, 1 hour
# Question
* Business usecase: doc usage falls due to increase in doc comments
* Proposed solution: Create weekly digest email to summarize the documents with top K comments
# Existing design
web app -> doc svc -> doc db
docdb: relational DB
schema: user table(userid,name,...), doc table (docid,name,createddate), comment table (useridFK, docidFK, commentid, text, createdDate)
# Final result
* Rejected. Proposed design does not take care of separation of concerns (workers shouldnt read from DB).
(self analysis): I was designing to address scale, reliability. workers reading from DB is OK (IMO) because relational DB are good for scaling out reads. But in the end, little things matter, its OK.
Update: Yes, I am wrong. I should rather fetched comments via Doc svc (not directly from doc db). Fair enough, I made a blunder, got rejected.
# Proposed Design
## Requirements gathering
150k comments/week, 100 comments/doc/week => 1.5 k docs /week emails
ML svc 50 comments/batch, horiz scalable, 200 comments
* email needed only if comments size > 50
* comments made in last week
// filter out < 50 comment/week documents
1.5 k * 2 invocations / week for ML svc
SLA for ML svc: p99 comment classification ? 10 min for 100 comments. can invoke
3000 * 100 comments -> 3000 * 10 mins (10 min/100 comments)
ML svc in parallel: 100 is throughput
multiple calls concurrently. horizontally scalable
configuration of doc DB: single DC
weekend email sending: top k comments/doc
workers set: 100 is active worker count. coordinator which is going to ensure worker count. an active failover worker. we can coordinate via configuration service like zookeeper.
300 mins of runtime each week (100 concurrency) -> 5 hours of runtime
In coordinator, have a cron trigger, singleton process which has a in memory scheduler task (quartz), at point in time (configurable)
* fetch the documents which had the activity for 1
* select distinct documentid from comment where createddate < 1-week-before-timestamp
* push doc-id to the queue <doc-id>
* the worker is going to fetch the document,
* fetch the comments (last 1 week) and split into multiple batches and invoke the ML svc to rank them. find out the top K comments, write to another queue which is going to be processed by the email digester svc
* get the doc-id, fetch all the comments, instead, fetch the count of the 1 week of comments so that we know how to batch it up.
X comments : divide it up into batches (50, <200 && >50)
* invoke the ML svc (in sequence) grpc messages (list comment text,comment-id), output is <list<comment-id,rank>>
* once all the comments are ranked, find out the top K comments
* push into the email queue <doc-id, top-k-comment-ids>, owner-id>
* only then commit the offset into the kafka queue
* email queue is sharded by the owner-id
* email digester svc ll have messages
<doc-id, list<top k comment-id>>
non functional req
* analytics is a big component
* live coding, 1 hour
simple question: get a paginated list of tasks from a live server (GET req, query params), filter it out and return a count
made complicated via java datetime and jackson APIs.
further complication:
I code using kotlin (had done so in the TPS as well). rec told me feel free to use any language (python, JS is preferred).
Issue: the live coding editor only supports python, JS, java.
So, I had to use java. And the inane java datetime, jackson API and java compilation errors and fixing took ton of time.
At the end, it was possibly a 5 min debugging and fixing minor issues which would have completed the solution.
behaviour, leadership
Standard amazon type questions
- Share the experience when you anticipated customer needs and delivered the solution by yourself.
- Tell me about the time when you received critical feedback and how you dealt with it and how
- Tell me any technically challenging issue and how did you solve it elegantly
Comments (1)

