Discover more from ByteByteGo Newsletter
EP29: Online Gaming Protocol
This week’s system design refresher:
Ace System Design Interviews
Online Gaming Protocol
Apple Pay vs. Google Pay
Telegram End-to-End Encryption
B-Tree vs. LSM-Tree
Markdown + Mindmap
Subscribe to get this newsletter every week
Scale from zero to millions of users, design a news feed system, design YouTube, and many more. The text-based course is designed to make you a better software engineer and ace the system design interview.
Note: This course contains the same content as my best-selling system design interview books (volume 1 and volume 2). If you already own those two books, there is no need to buy the course.
What protocol does online gaming use to transmit data? TCP or UDP?
A common practice is to use RUDP (Reliable UDP). It adds a reliable mechanism on top of UDP to provide much lower latency than TCP and guarantee accuracy.
The diagram below shows how reliable data delivery is implemented in online gaming to get eventually-synchronized states.
Suppose there is a big fight in a simulation shooter game. Characters A, B, and C open fires in sequence. How does the game server transmit the states from the game server to the game client?
Steps 1 and 2 - Character A opens fires. The packet (packet 0) is sent to the client. The client acknowledges the server.
Step 3 - Character B opens fire. The packet is lost during transmission.
Steps 4 and 5 - Character C opens fire. The packet (packet 2) is sent to the client. Since the last successfully delivered packet is packet 0, the client knows that packet 1 is lost, so packet 2 is buffered on the client side. The client acknowledges the server for the reception of packet 2.
Steps 6 and 7 - The server doesn’t receive the ack for packet 1 for a while, so it resends packet 1. When the client receives packet 1, all the subsequent packets become effective, so packets 1 and 2 become “delivered”. The client then acknowledges the server for the reception of packet 1. No packets are buffered at this point.
Apple Pay vs. Google Pay: Which is more secure?
Is Telegram secure?
Let’s first define what “secure” means. A “secure” chat in a messaging App generally means the message is encrypted at the sender side and is only decryptable at the receiver side. It is also called “E2EE” (end-to-end encryption).
In this sense, is Telegram secure? It depends.
Telegram’s usual private and group chats aren’t end-to-end encrypted
It generally means third parties can intercept and read your messages. Telegram uses the following approach for security:
The encrypted message is stored in Telegram servers, but split into several pieces and stored in different countries.
The decryption keys are also split and saved in different countries.
This means the hacker needs to get message chunks and keys from all places. It is possible but extremely difficult.
Secret chats are end-to-end encrypted
If you choose the “secret chat” option, it is end-to-end encrypted. It has several limitations:
It doesn’t support group chat or normal one-to-one chat.
It is only enabled for mobile devices. It doesn’t support laptops.
B-Tree vs. LSM-Tree
B-Tree is the most widely used indexing data structure in almost all relational databases.
The basic unit of information storage in B-Tree is usually called a “page”. Looking up a key traces down the range of keys until the actual value is found.
LSM-Tree (Log-Structured Merge Tree) is widely used by many NoSQL databases, such as Cassandra, LevelDB, and RocksDB.
LSM-trees maintain key-value pairs and are persisted to disk using a Sorted Strings Table (SSTable), in which the keys are sorted.
Level 0 segments are periodically merged into Level 1 segments. This process is called compaction.
The biggest difference is probably this:
B-Tree enables faster reads
LSM-Tree enables fast writes
If you use markdown and mindmap, you'll probably like this tool.
If you’re finding this newsletter valuable, consider subscribing to get it every week.