πŸ–₯️
Sunil Notebook
Interview Preparation
  • πŸ“’Notebook
    • What is this about ?
  • System Design
    • πŸ’‘Key Concepts
      • 🌐Scalability
      • 🌐Latency Vs Throughput
      • 🌐Databases
      • 🌐CAP Theorem
      • 🌐ACID Transactions
      • 🌐Rate limiting
      • 🌐API Design
      • 🌐Strong Vs eventual consistency
      • 🌐Distributed tracing
      • 🌐Synchronous Vs asynchronous Communication
      • 🌐Batch Processing Vs Stream Processing
      • 🌐Fault Tolerance
    • πŸ’ŽBuilding Blocks
      • πŸ”ΉMessage
      • πŸ”ΉCache
      • πŸ”ΉLoad Balancer Vs API Gateway
    • πŸ–₯️Introduction to system design
    • ⏱️Step By Step Guide
    • ♨️Emerging Technologies in System Design
    • β˜‘οΈSystem design component checklist
      • πŸ”·Azure
      • πŸ”ΆAWS
      • ♦️Google Cloud
    • 🧊LinkedIn feed Design
    • 🏏Scalable Emoji Broadcasting System - Hotstar
    • πŸ’²UPI Payment System Design
    • πŸ“ˆStock Broker System Design - Groww
    • πŸ§‘β€πŸ€β€πŸ§‘Designing Instagram's Collaborative Content Creation - Close Friends Only
    • 🌳Vending Machines - Over the air Systems
    • Reference Links
  • DSA
    • Topics
      • Introduction
      • Algorithm analysis
        • Asymptotic Notation
        • Memory
      • Sorting
        • Selection Sort
        • Insertion Sort
        • Merge Sort
        • Quick Sort
        • Quick'3 Sort
        • Shell Sort
        • Shuffle sort
        • Heap Sort
        • Arrays.sort()
        • Key Points
        • Problems
          • Reorder Log files
      • Stacks and Queues
        • Stack Implementations
        • Queue Implementations
        • Priority Queues
        • Problems
          • Dijkstra's two-stack algorithm
      • Binary Search Tree
        • Left Leaning Red Black Tree
          • Java Implementations
        • 2-3 Tree
          • Search Operation - 2-3 Tree
          • Insert Operation - 2-3 Tree
        • Geometric Applications of BST
      • B-Tree
      • Graphs
        • Undirected Graphs
        • Directed Graphs
        • Topological Sort
      • Union Find
        • Dynamic Connectivity
        • Quick Find - Eager Approach
        • Quick Find - Lazy Approach
        • Defects
        • Weighted Quick Union
        • Quick Union + path comparison
        • Amortized Analysis
      • Convex Hull
      • Binary Heaps and Priority Queue
      • Hash Table vs Binary Search Trees
  • Concurrency and Multithreading
    • Introduction
    • Visibility Problem
    • Interview Questions
    • References
      • System design
  • Design Patterns
    • ℹ️Introduction
    • πŸ’ Classification of patterns
    • 1️⃣Structural Design Patterns
      • Adapter Design Pattern
      • Bridge Design Pattern
      • Composite Design Pattern
      • Decorator Design Pattern
      • Facade Design Pattern
      • Flyweight Design Pattern
      • Private Class Data Design Pattern
      • Proxy Design Pattern
    • 2️⃣Behavioral Design Patterns
      • Chain Of Responsibility
      • Command Design Pattern
      • Interpreter Design Pattern
      • Iterator Design Pattern
      • Mediator Design Pattern
      • Memento Design Pattern
      • Null Object Design Pattern
      • Observer Design Pattern
      • State Design Pattern
      • Strategy Design Pattern
      • Template Design Pattern
    • 3️⃣Creational Design Patterns
      • Abstract Factory Design Pattern
      • Builder Design Pattern
      • Factory Method Design Pattern
      • Object Pool Design Pattern
      • Prototype Design Pattern
      • Singleton Design Pattern
    • Java Pass by Value or Pass by Reference
  • Designing Data-Intensive Applications - O'Reilly
    • Read Me
    • 1️⃣Reliable, Scalable, and Maintainable Applications
      • Reliability
      • Scalability
      • Maintainability
      • References
    • 2️⃣Data Models and Query Languages
      • Read me
      • References
    • Miscellaneous
  • Preparation Manual
    • Disclaimer
    • What is it all about?
    • About a bunch of links
    • Before you start preparing
    • Algorithms and Coding
    • Concurrency and Multithreading
    • Programming Language and Fundementals
    • Best Practices and Experience
  • Web Applications
    • Typescript Guidelines
  • Research Papers
    • Research Papers
      • Real-Time Data Infrastructure at Uber
      • Scaling Memcache at Facebook
  • Interview Questions
    • Important links for preparation
    • Google Interview Questions
      • L4
        • Phone Interview Questions
      • L3
        • Interview Questions
      • Phone Screen Questions
  • Miscellaneous
    • 90 Days Preparation Schedule
    • My Preparation for Tech Giants
    • Top Product Based Companies
  • Links
    • Github
    • LinkedIn
Powered by GitBook
On this page
  • Introduction to Caching
  • Caching Strategies
  • Cache Eviction Policies
  • Handling Cache Invalidation
  • Real-World Example

Was this helpful?

Edit on GitHub
  1. System Design
  2. Building Blocks

Cache

PreviousMessageNextLoad Balancer Vs API Gateway

Last updated 10 months ago

Was this helpful?

Interviewer Conversation on Caching Techniques

Introduction to Caching

Interviewer: Can you briefly explain what caching is and why it’s important in system design?

Candidate: Yes, In my recent project i have used caching to retrieve data fast. This is one of the performance techinque. Caching is a technique used to store copies of frequently accessed data in a faster storage medium to improve performance and reduce latency. It’s crucial in system design because it helps in reducing the load on databases and backend services, leading to faster response times and improved scalability.

Caching Strategies

Interviewer: What are some common caching strategies used in system design?

Candidate: There are many caching strategies, few of them are as below:

  1. Cache-Aside : Data is loaded into the cache only when it's requested. If the data isn’t in the cache, it’s fetched from the database and then stored in the cache for future requests.

  2. Write-Through Cache: Data is written to both the cache and the underlying database simultaneously, ensuring that the cache is always up-to-date with the database.

  3. Write-Behind Cache: Data is written to the cache first and then asynchronously written to the database. This strategy can improve performance but requires careful handling of data consistency.

Studio Link:

Cache Eviction Policies

Interviewer: How do cache eviction policies work and why are they important?

Candidate: Most of the developers face issues in the cache eviction policies. I am one of them. Cache eviction policies determine which items should be removed from the cache when it becomes full. They are important because they help manage memory usage and ensure that the cache remains efficient. Common policies include LRU , LFU , and FIFO . Choosing the right policy depends on the access patterns and specific requirements of the application.

Handling Cache Invalidation

Interviewer: Ok great. How do you handle cache invalidation to ensure data consistency?

Candidate: Cache invalidation is crucial to maintaining data consistency between the cache and the underlying data source. Techniques for cache invalidation include:

  1. Time-Based Expiration: Data is automatically invalidated after a specified time period.

  2. Event-Driven Invalidation: Cache entries are invalidated based on specific events, such as updates to the database or changes in application state.

  3. Manual Invalidation: Developers explicitly remove or update cache entries when changes occur.

This totally depends on the consistency requirements and performance considerations.

Real-World Example

Interviewer: Can you give an example of how you would implement caching in a real-world application?

Candidate: Sure! For an e-commerce website, I would use a cache-aside strategy to cache product details. When a user requests product information, the system first checks the cache. If the data is not found, it retrieves it from the database, stores it in the cache, and then serves the data to the user. I would also use a time-based expiration policy to ensure that product details are updated periodically. Additionally, I might use a write-through cache for critical data like user sessions to keep it in sync with the database.

πŸ’Ž
πŸ”Ή
https://studio.sunilgudivada.dev/flow/caching-techniques
Caching Techinques
Cache Aside Strategy