Network Protocols

Transmission Control Protocol (TCP) TCP Principles and Mechanisms Key features: Connection Establishment: Three-way handshake (SYN, SYN-ACK, ACK) Reliable Delivery: Acknowledgment and retransmission Flow Control: Sliding window mechanism Congestion Control: Slow start, congestion avoidance, fast retransmit, and fast recovery Ordered Data Transfer: Sequence numbers Error Detection: Checksum Example of TCP header: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Port | Destination Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Acknowledgment Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data | |U|A|P|R|S|F| | | Offset| Reserved |R|C|S|S|Y|I| Window | | | |G|K|H|T|N|N| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Checksum | Urgent Pointer | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | data | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ TCP Performance Characteristics Throughput:...

October 4, 2024

Operating System Interview

Explain the difference between a process and a thread. Process: Independent execution unit Has its own memory space Heavyweight, more resources Isolated from other processes Thread: Lightweight unit of execution within a process Shares memory space with other threads in the same process Less resource-intensive Can communicate easily with other threads in the same process How do processes and threads communicate Process communication methods: Pipes and named pipes Shared memory Message queues Sockets Signals Thread communication methods:...

October 4, 2024

Subnet and Subnet

What is a Subnet? A subnet is a way to divide a large network into smaller, more manageable pieces. Think of it like dividing a big city into neighborhoods. Each subnet (neighborhood) has its own group of devices (houses), but all are still part of the same overall network (city). What is a Subnet Mask? A subnet mask is a number used to help identify which part of an IP address belongs to the network (city) and which part identifies the device (house)....

October 4, 2024

Epoll

epoll (Linux): An Efficient I/O Multiplexing Mechanism epoll operates on an event-driven model, meaning it only notifies the application when an event occurs on a specific file descriptor, unlike select and poll which poll all descriptors regardless of activity. This drastically reduces overhead, especially when managing numerous connections. Key Features and Functionality The core functionality revolves around three system calls: epoll_create(size): Creates an epoll instance and returns an epoll file descriptor....

October 3, 2024

MySQL's Transaction Isolation Levels

SQL Transaction Isolation Levels Transaction isolation levels define the degree to which the operations in one transaction are visible to other concurrent transactions and the types of reads and writes that are allowed. Comparison Table Isolation Level Dirty Read Non-repeatable Read Phantom Read READ UNCOMMITTED Yes Yes Yes READ COMMITTED No Yes Yes REPEATABLE READ No No Yes SERIALIZABLE No No No Explanation of Isolation Levels 1. READ UNCOMMITTED This is the lowest isolation level....

October 3, 2024

Eval and Evalsha

Overview EVAL and EVALSHA are Redis commands used to execute Lua scripts within the Redis server. They differ primarily in how they handle script loading and execution: EVAL: This command takes the Lua script as an argument. Redis parses and hashes the script every time EVAL is called. This adds overhead, especially for frequently executed scripts. EVALSHA: This command takes the SHA1 hash of the Lua script as an argument. Redis retrieves the script from its internal cache using this hash....

October 2, 2024

Go Memory Allocation

How does Go handel memory allocation Memory Allocator Overview The Go memory allocator uses a hierarchical structure: Heap: The main memory area where dynamically allocated objects reside. Spans: Large blocks of memory (usually 8KB) used to allocate objects. Objects: Individual allocated pieces of memory. graph TD Heap --> Span1[Span 1] Heap --> Span2[Span 2] Heap --> Span3[Span 3] Span1 --> Obj1[Object 1] Span1 --> Obj2[Object 2] Span2 --> Obj3[Object 3] Span2 --> Obj4[Object 4] Span3 --> Obj5[Object 5] Size Classes Go uses size classes to group objects of similar sizes....

October 2, 2024

Redlock Algorithm

Redlock Algorithm: Distributed Lock Management Introduction The Redlock algorithm is a distributed lock algorithm designed to provide a reliable locking mechanism in distributed systems. It was proposed by the Redis community as a way to implement distributed locks using multiple independent Redis instances. Purpose The main purpose of the Redlock algorithm is to ensure that: Mutual exclusion is guaranteed Deadlock free operation is possible Fault tolerance is achieved up to a certain degree Algorithm Overview The Redlock algorithm uses multiple Redis instances (typically 5) to achieve consensus on lock acquisition and release....

October 2, 2024

Go's GMP Model

What is the GPM model in Go? GMP Model The GMP model is the cornerstone of Go’s runtime scheduler. G (Goroutine): Represents a goroutine, which is a lightweight thread of execution. Contains the stack, the instruction pointer, and other information important for scheduling. Many Gs can exist at the same time. P (Processor): Represents a logical processor, which can be thought of as a context for scheduling. Acts as a local scheduler, managing a queue of runnable goroutines....

October 1, 2024

Golang Interview

How does Go handle dependencies? Go uses a module system for dependency management. The go.mod file specifies the module’s dependencies and their versions. The go get command is used to download and install dependencies. What is the difference between go run and go build ? Feature go run go build Purpose Compile and run in one step Compile to a permanent executable Output Temporary executable (deleted) Permanent executable on disk Use Case Quick testing of small programs Building applications for deployment Performance Slower due to temporary compilation Faster execution of compiled binary Debugging Limited debugging capabilities Supports debugging and profiling Configuration Options None Various options for customization Use go run for quick tests and development....

September 14, 2024