On this e-newsletter, we’ll cowl the next subjects:
-
TCP or UDP for Zoom?
-
Why is Kafka quick? (YouTube movies)
-
Distributed SQL
-
Blocking vs non-blocking queue
TCP or UDP for Zoom?
Which protocol does Zoom use for video streaming, TCP or UDP?
Let’s assessment the variations first.
🔹 The first distinction between TCP and UDP is that TCP is connection-based whereas UDP is connectionless.
Connection-based: It implies that every one messages will arrive and arrive within the appropriate order.
Connectionless: It doesn’t assure order or completeness.
🔹 The second distinction is that UDP is quicker than TCP.
– UDP doesn’t require ACK message again
– UDP has no move management
– No duplication verification on the receiving finish
– Shorter header
UDP sacrifices correctness for pace. Customers typically choose clean video calls and UDP is certainly the default alternative for Zoom.
Over to you: the HTTP protocol was once based mostly on TCP, however the newest protocol HTTP/3 is predicated on UDP. Are you aware why?
Why is Kafka quick? (YouTube movies)
Primarily talked about two methods: Sequential I/O and Zero-copy
Distributed SQL
What’s Distributed SQL? Why do we want it?
Google’s Spanner popularized the time period “distributed SQL” database in 2012. Distributed SQL databases mechanically replicate knowledge throughout a number of nodes and are strongly constant. Paxos or Raft algorithms are generally used to attain consensus throughout a number of nodes.
Examples of Distributed SQL databases: Google Spanner, Amazon Aurora, CockroachDB, YugabyteDB, TiDB, and many others.
A number of weeks in the past, I met the CTO of TiDB ED Huang and some different crew members. We mentioned how Distributed SQL databases developed and the way TiDB developed its personal open-sourced database. After that dialog, I learn extra documentation/supply code about it and I discovered it to be an fascinating case examine. I need to share my studying right here.
Phrases:
OLTP = On-line transactional processing
OLAP = On-line analytical processing
HTAP = Hybrid transaction/analytical processing
🔹The lifetime of an OLTP question (marked with blue sequence numbers):
Step 1. A consumer sends a MySQL question and the question is interpreted by TiDB, a stateless SQL layer that interprets the MySQL protocol.
Step 2: TiDB requests knowledge mapping/placement info from the location driver (PD).
Step 3: PD responds with knowledge mapping/ placement directions & timestamp.
Step 4: TiDB executes queries on TiKV servers (row-based storage).
Step 5, 6: Question outcomes are despatched again to the consumer.
🔹The lifetime of a posh OLAP question: marked with yellow sequence numbers.
Over to you: do you assume the phrases OLTP and OLAP have turn out to be out of date or are they nonetheless very related? When ought to we use distributed SQL databases vs conventional relational databases?
Blocking vs non-blocking queue
How can we implement a non-blocking queue? What are the variations between blocking and non-blocking algorithms?
The phrases we use when discussing blocking and non-blocking algorithms will be complicated, so let’s begin by reviewing the terminology within the concurrency space with a diagram.
🔹blocking
The blocking algorithm makes use of locks. Thread A acquires the lock first, and Thread B may await arbitrary prolonged intervals if Thread A will get suspended whereas holding the lock. This algorithm might trigger Thread B to starve.
🔹non-blocking:
The non-blocking algorithm permits Thread A to entry the queue, however Thread A should full a job in a sure variety of steps. Different threads like Thread B should starve because of the rejections.
That is the primary distinction between blocking and non-blocking algorithms: The blocking algorithm blocks Thread B till the lock is launched. A non-blocking algorithm notifies Thread B that entry is rejected.
🔹starvation-free:
Thread Hunger means a thread can’t purchase entry to sure shared assets and can’t proceed. Hunger-free means this example doesn’t happen.
🔹wait-free:
All threads can full the duties inside a finite variety of steps.
𝘞𝘢𝘪𝘵-𝘧𝘳𝘦𝘦 = 𝘕𝘰𝘯-𝘉𝘭𝘰𝘤𝘬𝘪𝘯𝘨 + 𝘚𝘵𝘢𝘳𝘷𝘢𝘵𝘪𝘰𝘯-𝘧𝘳𝘦𝘦
➡️ Non-Blocking Queue implementation
We are able to use Evaluate and Swap (CAS) to implement a non-blocking queue. The diagram beneath illustrates the algorithm.
➡️ Advantages
1. No thread suspension. Thread B can get a response instantly after which resolve what to do subsequent. On this means, the thread latency is vastly decreased.
2. No deadlocks. Threads A and B don’t await the lock to launch, which means that there isn’t a chance of a impasse occurring.
Different issues we made:
Our bestselling e-book “System Design Interview – An Insider’s Information” is obtainable in each paperback and digital format.
Paperback version: https://geni.us/XxCd
Digital version: https://bit.ly/3lg41jK
New System Design YouTube channel: https://bit.ly/ByteByteGoVideos