Professional Documents
Culture Documents
Round 4: (System Design) : Weekends - Aspx
Round 4: (System Design) : Weekends - Aspx
We have 500TB key - value database. Need design system that will value by key. You
can compute how many machines you need. Database sharding , backups . What will
be if one of machines will die?
Make a sharding of the database by key. Let's say you have 500 machines with 1 TB for each.
Make sure to have a load balancer to point to a right shard based on the key.
What If 500TB becomes 1000TB, USE the consistent
hashing http://deepakdhakal.com/post/2019/08/10/Consistent-Hashing-Save-Your-
Weekends.aspx
for each machine, make sure to add another 2 more backups and do an eventual consistency
policy on update.
Design a system like Google photos homepage that can show recent photos of a user along
with the shared photos.
Interest areas -
// todo
// todo
// todo
Example:
m.addService("A");
m.addService("B");
m.addServiceCall("A", 1, "abc");
m.addServiceCall("A", 5, "abec");
m.addServiceCall("B", 3, "ac");
Follow-up:
What if you also had to filter by service?
Hi,
Well, I think this question is very straightforward. The thing is... store the services, sorting by time.
There are a plenty of data structures that can make it for you.
Solution 1
Worst solution. You create a Linked list (or an array) and when a
call getAllServiceCallsBetweenTimes() is triggered you walk through this list and adds
every task that satisfies the condition into a temporary list and return it.
It is O(n) in time, since you have to walk through the entire list every time this call is triggered
and O(n) (worst case) in space, cause you have to create another structure to accommodate
the services to return.
Solution 2
Store in a BST. Every time a new element is added to the tree you add it (one problem here is
to keep the tree a BST). Once a call is made you just have to find all services in a specific sub
tree range. Since a search in a BST is O(log n) you would have an exceptional performance
improvement.
Solution 3
Sometime we forget about a very nice data structure... heap. The heap keeps the smaller (or
greater) element in the top. All you have to do is.. keep the services in this heap and go
removing and once you find the first element that is in the lower range you keep tracking
and finish when found the first element greater than the higher boundary. It is also a O(log n)
structure and can be very helpful in this situation.
If you want to add filter by service, after getting all elements from the range, look for the service you
want. Or, just discard elements that do not match the service criteria when building the returning list.
HTH
Artur
Heap is a good idea! I was thinking maybe balanced BST, which may have better average case
performance on range queries. Worst case complexity for both would be the same though
Also asked about tradeoff on ajax polling, long polling, & web socket for each of the
functionality and ask me which to use for each.
Please discuss!
Ans:
Here is what I'm thinking:
After clarifying the feature requirements, ask about the consistency/availability/latency requirements.
Then talk about the high level design, drop some boxes, walk through the features one by one. Then
describe how you solve the issue, what's the inner database design, API design, communication
protocol inside it. Make sure you keep on talking and gain some guidance from the interviewer,
understand which part he wants the most.
Sometimes I found it doesn't mean you need to go over each component of the system, interviewer
may only want to focus on some small part. This means the system design process may vary a bit
totally depending on the interviewer.
*Send gifts to room owner with a message broadcasted to all users in the room
The action here contains 1. send gifts, clarify with the interviewer whether you need to describe this
part. 2. After send gifts, the system will generate a message broad cast to all users in the root, so the
system itself could generate the send gift message, then figure out who are the users in the chat
room, go to the user id <-> connection object hash map table figure out which connection is used
to connect to the customer, then send the message through the connection.
You may want to talk about if the user is offline, then you need to queue/store the message in some
place, then send later. Either after user come online or send notification.
*Playback video function should display gifts, screen messages, & chat to be shown again
Firstly you want to talk about video has the time line, then gifts, screen messages and chats are all
having the time line, you may want to talk about the algorithm of this implementation, like you have
a few components hooked to the video timeline, then those components will add
gifts/message/chats into the chatroom/video when the video timeline hits.
Hey guys,
I was interviewed at Twitch earlier This was the question that was asked for sys design.
Given
There is already defined Twitch video stream and chat box with a viewer count
There is a User Service that requires User_id and provides User's Age and Gender.
Approach
I had a WebSocket approach where the user devices provide heartbeat checks to server
and Server produces data analytics on active users.
Google | Phone Screen | Design a webpage that can show 10M+ users status
Design a webpage that can show 10M+ users status including name, photo, badge, points.
1. depending on how you design the system and layout. It's an open-ended and progressive
question that you'll define along the way. I gave an example of infinite scrolling / sliding
window to represent how to update / store users.
2. a fetch is the first step, it follows up with (1) implementing the model / view (as in MVC)
logics for updating the page (2) DOM API manipulations with scroll events and pass to (1)