Koolaidrain

Systems Design 1

Jul 20th, 2023 (edited)
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.55 KB | None | 0 0
  1. 8:10
  2.  
  3. What is read-through cache? What is look-aside cache?
  4. - If the cache talks to the DB, it's a read-through cache
  5. - If it doesn't, it's a look-aside cache. Like Redis or Memcache
  6.  
  7. Misc
  8. - TAO was read-through with a pool of existing connections to the DB
  9. - memcache GET(key) SET(key, value) DEL(key)
  10.  
  11. Apache process pool? (2005) I thought it was threads? :(
  12.  
  13. It's 2005. Someone wrote a look-aside in-memory cache with GET SET DEL. It's a black box. Basic Apache webserver and all.
  14. "I would like to put this on the Internet". How do I design a method to put this on the Internet.
  15. They can put their service on Thrift or something similar
  16.  
  17. ? Thrift is HTTP/2.0. What is the difference between HTTP 1/2/3?
  18. Revisit TCP vs UDP (congestion control, exponential backoff, transmission control, retransmits with sequence numbers)
  19. Revisit OSI model
  20. Where do you slot a NIC into a motherboard?
  21. How does the packet get to the proper process? What happens if you overfill the socket queue? NETBUF?
  22. How does an outgoing packet get to the local NIC?
  23. How do I find my local gateway router? Is it 192.168.1.1? And DHCP keeps a LAN's nameservers by MAC.
  24. Local DNS is recursive - has the IP of the global root nameserver. Everything else is iterative.
  25. What are DNS records? A IPv4, AAAA IPv6, CNAME alias
  26. How do you do Secure DNS? DNS SEC?
  27. What is DNS based on, TCP or UDP? Both? It's UDP unless the return is too big: DNSSEC, many records, IPv6, and/or zone transfers.
  28. - https://serverfault.com/questions/404840/when-do-dns-queries-use-tcp-instead-of-udp
  29. What are the different AS protocols? When would you use BGP or OSPF? BGP is eventually consistent, OSPF is always consistent (small nets). BGP is shortest path based on minimum hops. Explain how BGP is eventually consistent.
  30. What are the different AS - AS agreements and traffic?
  31. Open internet to AWS - NAT gateways are LBs. Probably an edge proxy (including NAT gateway) (something with firewall rules and DDOS protection)
  32. How do virtual networks work? How do proxies work? How does DSR work?
  33. How do generic IDLs work? How are Thrift/Protobufs different?
  34. Read up on REST and SOAP (and XML?)
  35. Read up on Thrift inter-machine communication.
  36. Look up RPC and verify whether it's TCP?
  37.  
  38. Q: Justin Bieber posts daily on your blog. How long does it take for him to post something? (Pointy headed question)
  39. Post is ~32K (1K words tumblr, 1B char, 32B word, small metadata) and MTU is 1500 (9k for large MTU) - 20 packets
  40. Average upload speed is 20 mbps - 20/8 MBps - 32KB / 20/8 MBps - 13 ms - how do you break down "upload speed"? It's a rough average... :(
  41. Subsequent read should fill the cache, unless you have a read-through cache - which always fills the cache (most are LRU).
  42. Subsequent read can be ASYNC with returning to the user.
  43.  
  44. Assume 20 Mbps is average for servers too because servers can be in AWS while DB is in MongoDB, etc.
  45. Cache should be colocated within the same subnet + facility. FB's TAO is deployed with the webserver fleet, intra-datacenter. 1-5ms round trip.
  46. Cache requests are NEVER cross-regional. So 13*4 = 52 ms total.
  47. Distributed Job Execution Engines are not popular in the open internet. :( Use Ansible or Terraform or new parallel.
  48. Read up on BitTorrent interview question design for distribution. E/W traffic is bottlenecked on individual_server + s2s OR TOR link b/w.
  49.  
  50. Now a single memcache server is not enough, how do I distribute this to more memcached servers? LRU is "churning" i.e. low hitrate - working memory's content is changing all the time.
  51. When JB posts a lot and millions are online, bottlenecks of single-server design everywhere are:
  52. - Server bandwidth bottleneck immediately. Solve this with multiple webservers and 1+ load balancers.
  53. Pareto principle: 80/20 rule. RULE OF THUMB. For LBs and webservers? What are reactive sockets? What is QUIC?
  54. Examples of popular LBs: AWS LBs, Envoy, etc.
  55. 1 LB is usually good for hundreds of webservers but it also depends on the (stateless) load being proxied.
  56. FB uses pick 2. Before the variance was 20% from server to server with balls + buckets, then 1% after pick 2.
  57. Signals for "cache needs to scale" - high CPU, hitrate seasonality (variance over time, teens use it on fridays, etc), working memory, aim for 50% failover
  58. Low hit rate - your users could be very different (servers won't naturally tend toward stability), OR you need more working memory
  59. Reads are 1000x more frequent than writes
  60. High CPU and low hitrate are the signals for too much cache load. I/O is the signal for too much DB load.
  61. Read about DB indexing. It's an R/B tree on DB columns. Good for reads but not writes b/c it means writes must update the tree.
  62. To scale the cache, add a hashring, key % HIGH_NUMBER, when you add/remove a machine, you reassign some non-consecutive shards to new machine.
  63. Frequently you do "maintenance" to "defragment" the hashring - "shard balancing". At FB we had 300K shards for 1B users.
  64. FB's content keyed had FBID, which NTYPE is an intrinsic part of - could be a user, post, or comment.
  65. The hashing algorithm was assumed to be uniform - A FBIDs to <B SHARDS> to C cache servers. Eventually, this changed - some shards were 100x hotter than others in terms of CPU. So each shard was given a weight between 0-1 proportional to the load they drew over the last day.
  66. This helped them determine the mapping to the C cache servers better. Ten 0.1 shards or 1 1.0 shards. Total weight * number of shards = shard space. These shards were shifted daily. Less expensive shards were moved first. This was called shard balancing.
  67. More DBs - Same thing as shards but much less frequent rebalancing. This is just about data placement - moving shards around.
  68.  
  69. Common pitfall
  70. - Caches are great with hot reads, but hot reads + hot writes is bad --> because the app needs to trigger cache backfill, else you'll have very high inconsistency.
  71. - Hot read, cold cache: Thundering herd problem on the database. Users all come in asking for OLD content, which thunders the DB with SETs. Deduplicating requests is too hard - keeping a bloom filter is too much. You MUTEX on the DB shard + content KEY. This is called "lease get, lease set". Ask the cache for a "lease" - create the key in memcache and write the lease owner in cache. Other users can see that the content is cold but the lease is taken by another guy. Tell other users to try again later. Implemented in FB in 2012. Important for virality.
  72. Read about NGINX.
  73.  
  74. SYSTEMS
  75. - Memory is used for processes, scheduling, connections, etc. An argument for keeping swap on is "memory pressure". HOW TO KEEP IT ON/OFF?
  76. - Whats the data structure of a page table? Info in a PT entry? Either the content from memory or the location in swap space.. VERIFY THIS
  77. - READ about page faults - apparently the kernel internally page faults - major fault and minor fault? MEMORY MANAGEMENT UNIT
  78. https://scoutapm.com/blog/understanding-page-faults-and-memory-swap-in-outs-when-should-you-worry
  79. - RECALL COW - you don't copy over the stack until you change the stack. READ MORE
  80. - RECALL boot loading
  81. - RECALL signal handling
  82. - RECALL debugging
  83. - RECALL vmstat
  84. - RECALL corrupt files
  85. - recall bpf
  86.  
  87. Datadog Final Round
  88. - Design: Build a startup from the ground up that notifies users about airline ticket deals within 10 minutes if they haven't been emailed within 24h. The company invested in a Data Science team that has a Data Model which determines if tickets are deals.
  89. - Coding II: Given a stream of metric|value|tags_csv strings AND a set of search tags, output all tags associated with all search tags.
  90.  
  91. TO DO: write a better explanation for NIC investigation
Add Comment
Please, Sign In to add comment