FAANG | Onsite | Intern | System Design Stock
Anonymous User
3529

Design a system that will be able to display top 100 companies in sorted order based on the amount of stocks they have.

So the system recieves trades, what these trades have are:

  • Company Name
  • Amount of Stock

Assume there will be 1 Million trades incoming and you need to output the top 100 companies that have the most stock.

Example:
  1. trade 1 comes in Vodafone 100 Stock
  2. trade 2 comes in Microsofy 40 stock
  3. trade 3 comes in Vodafone 50 stock
  4. trade 4 comes in Google 10 stock

so at the end we would have the order of:

  1. Vodafone 150 - here you ssee vodafone has it 100+50 summed up.
  2. Microsoft 40
  3. Google 10

Now i haven't done system design before so i was new to this but this was my solution:

  • Have multiple servers, saw some vids on vertical and horizontal scaling so i just said that
  • each server will store its own top 100 and at the end we would merge
  • he asked how would i distribute the loads; i didnt know much but i just said first incoming trade goes to one server then the next incoming trade goes to the one after; apparently this is called round-robin
  • after that we moved onto hashing an incoming trade and mapping it to a server; because we want the same company to go to same server or we might have half in different servers and lose them
  • after this i got lost for a bit and he told me some stuff about using a cache but i wasnt able to keep up
  • we then moved onto the algo design i sugessted using min-heap in each server and adding/poping elements since heap stores them well. 1 class for ComapnyVol and one for the actual heap
  • he also helped me at the end because i had to make sure when we get same company name in a heap we dont put them as duplicates and also make sure to the heap is sustained when we combine multiple trades of same company

after that we i asked questions and we ended there.

Based on this was i right with the Min-heap and the server stuff. TBH i didnt prepare system design too much because i thought it was going to be a leetcode round.

Do you guys think i did good enough to get the offer?

Comments (4)