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?...

September 13, 2024

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....

September 12, 2024

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....

September 9, 2024

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!...

September 8, 2024

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....

September 7, 2024

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....

September 7, 2024

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:...

September 7, 2024

Mysql Interview

What are the main MySQL storage engines and their differences? MySQL supports multiple storage engines, each with distinct characteristics: InnoDB: Default engine since MySQL 5.5 Supports ACID transactions Provides row-level locking Supports foreign keys and relationship constraints Uses clustered indexes MyISAM: Older engine, used as default before MySQL 5.5 Non-transactional Table-level locking Faster for read-heavy operations Supports full-text indexing Memory (HEAP): Stores data in RAM for fast access Non-persistent (data lost on restart) Useful for temporary tables and caches Archive:...

September 7, 2024

Mysql's Join Types Comparison

Input Tables INNER JOIN INNER JOIN returns only the rows where there’s a match between both tables based on the join condition. SELECT A.ID, A.Name, B.ID, B.Department FROM A INNER JOIN B ON A.ID = B.ID LEFT JOIN LEFT JOIN returns all rows from the left table (A), and the matched rows from the right table (B). If there’s no match, NULL values are used for the right table columns....

September 7, 2024

Prometheus

What is Prometheus? Prometheus is an open-source systems monitoring and alerting toolkit. It collects and stores metrics as time series data, allowing for flexible querying and real-time alerting. What are the main components of Prometheus? The main components of Prometheus are: Prometheus server (for scraping and storing time series data) Client libraries (for instrumenting application code) Push gateway (for supporting short-lived jobs) Exporters (for services that don’t expose Prometheus metrics directly) Alertmanager (for handling alerts) How does Prometheus collect metrics?...

September 7, 2024