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. [Read More]

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. [Read More]

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. [Read More]

System Design

How to Solve Cache Penetration? Cache penetration occurs when requests for non-existent data bypass the cache and hit the database repeatedly. Solutions include: Caching Empty Results: Store empty results for non-existent keys with a short expiration time. Bloom Filters: Use a Bloom filter to check if a key exists before querying the database. Rate Limiting: Limit requests for certain keys to prevent overwhelming the database with requests for non-existent data. How to Solve Cache Avalanche? [Read More]

Go Pprof

Overview of Pprof pprof is a tool that comes with Go’s standard library and is used for collecting and viewing profiling data. It can collect different types of profiles including: CPU Profile: Measures where the program spends most of its time. Memory Profile: Measures the amount of memory allocated and retained. Block Profile: Measures where the program spends time waiting for synchronization primitives. Mutex Profile: Measures contention on mutexes. Setting Up pprof To use pprof, you need to import the net/http/pprof package and set up HTTP server to serve the profiling data. [Read More]

Redis, Pika, and Codis

Comprehensive Technical Analysis: Redis, Pika, and Codis Introduction In the realm of distributed data storage and caching systems, Redis, Pika, and Codis represent three distinct approaches to solving scalability, persistence, and performance challenges. This comprehensive analysis delves deep into the architectures, features, and use cases of these systems, providing detailed code examples and visual representations to facilitate a thorough understanding. Redis Redis (Remote Dictionary Server) is an open-source, in-memory data structure store that has become a cornerstone in modern application architectures. [Read More]

Git

GIT CHEAT SHEET CREATE Clone an existing repository: $ git clone ssh://user@domain.com/repo.git Create a new local repository: $ git init LOCAL CHANGES Changed files in your working directory: $ git status Changes to tracked files: $ git diff Add all current changes to the next commit: $ git add . Add some changes in <file> to the next commit: $ git add -p <file> Commit all local changes in tracked files: $ git commit -a Commit previously staged changes: $ git commit Change the last commit (do not amend published commits! [Read More]
Git 

Go Garbage Collection

How does garbage collection work in Go? Garbage Collection Go uses a concurrent, tri-color mark-and-sweep garbage collector with write barriers. Garbage Collection Phases Mark Setup: Preparation for marking phase. Marking: Identifying live objects. Mark Termination: Completion of marking phase. Sweep: Reclaiming memory from dead objects. graph LR A[Mark Setup] --> B[Marking] B --> C[Mark Termination] C --> D[Sweep] D --> A Tri-Color Algorithm Objects are divided into three sets: White: Potentially garbage objects. [Read More]

Go's Sync

sync.Mutex // Mutex provides mutual exclusion for shared resources. type Mutex struct { state int32 // State of the mutex (locked/unlocked) sema uint32 // Semaphore for blocking goroutines } // Lock acquires the mutex, blocking if necessary. func (m *Mutex) Lock() { // Check if already locked; if so, block until unlocked. } // Unlock releases the mutex. func (m *Mutex) Unlock() { // Update state and unblock waiting goroutines if any. [Read More]

Jaeger

direct-to-storage architecture architecture with Kafka as intermediate buffer What is Jaeger? Jaeger is an open-source, end-to-end distributed tracing system. It helps monitor and troubleshoot transactions in complex, microservices-based architectures. What problem does distributed tracing solve? Distributed tracing helps in understanding the flow of requests through a distributed system, identifying performance bottlenecks, and diagnosing issues in microservices architectures. What are the main components of Jaeger? The main components of Jaeger are: [Read More]