19. System Design: Distributed Cache and Caching Strategies | Cache-Aside, Write-Through, Write-Back

Поділитися
Вставка
  • Опубліковано 28 чер 2024
  • ➡️ Notes: Shared in the Member Community Post (If you are Member of this channel, then pls check the Member community post, i have shared the Notes link there)
    ➡️ Join this channel to get access to member only perks:
    / @conceptandcoding
    Topics i have covered:
    - What is Cache, when to use?
    - How Distribute Caching works?
    - Caching Strategies and its Pros and Cons
    (Cache Aside, Read Through, Write Around, Write Through and Write Back Cache)
    Chapters:
    00:00 - Introduction
    00:53 - What is Caching
    05:31 - What is Distributed Caching
    10:33 - Cache-Aside Caching Strategy
    18:44 - Read Through Caching Strategy
    22:34 - Write Around Caching Strategy
    27:06 - Write Through Caching Strategy
    31:48 - Write Back Caching Strategy
    Consistent Hashing Video: • 6. Consistent Hashing ...
    Other Playlist:
    HLD: • High Level Design from...
    LLD : • Low Level Design from ...
    JAVA: • JAVA from Basics to Ad...
    You can also connect with me 1:1 on Topmate:
    topmate.io/concept_coding
    Join this channel to get access to perks:
    / @conceptandcoding
    #caching #systemdesign #Redis

КОМЕНТАРІ • 41

  • @rv0_0
    @rv0_0 10 місяців тому +4

    HI brother. I cannot appreciate the videos enough.
    From last two days I am binge watching.
    Please upload more videos on designing the system.

  • @sdash2023
    @sdash2023 Рік тому +3

    A much needed concept. Thanks for this lesson. Sir please bring the part 2 quickly. And also how can we relate redis here. If you could explain a usecase with redis server.

    • @ConceptandCoding
      @ConceptandCoding  Рік тому +1

      Sure , redis is a distributed Cache only, so all which i explained is applicable to redis also

  • @sumitbasu5146
    @sumitbasu5146 6 місяців тому +1

    Hi Shreyansh, Thank u for the wonderful video and the contributions u made so far. One question related to the second part of this video or when the Cache Eviction Policy video will be out? OR am I missing something here?

  • @ujjalroy1442
    @ujjalroy1442 Рік тому

    Very useful video..... indeed is one of the best i have ever seen

  • @sraynitjsr
    @sraynitjsr Рік тому

    Thanks Shreyansh Sir, Loved It.....

  • @guy_whocode
    @guy_whocode 11 місяців тому

    Bahut Sahi Shreyansh.....Good Job

  • @sachinmagdum
    @sachinmagdum 7 місяців тому

    Hi Shreyansh, Does the "write around" strategy effectively solve the consistency problem? Imagine this scenario: at T1, thread-A reads a record from the database. At T2, thread-B writes the latest value of that record to the database. Subsequently, at T3, thread-B invalidates the cache, signaling that the record is no longer valid. However, at T4, thread-A updates the cache with the stale value it read at T1.
    This raises concerns about the efficacy of the "write around" approach in ensuring consistency. Despite the cache invalidation at T3, the update at T4 reintroduces a stale value, potentially leading to data inconsistencies. Let me know your thoughts around this.

  • @ManishTiwari-or8zt
    @ManishTiwari-or8zt Місяць тому

    Can you please make video to implment caching technique in distributed system.

  • @mitulgupta9258
    @mitulgupta9258 11 місяців тому

    Hi Shreyansh! Just one question - In Write Around Cache we are marking the entry in cache as dirty if it is updated on DB. Do we also need a 2 phase commit in this case as in Write Through Cache? Because updating the value as dirty in cache is a necessary operation to be completed along with DB update.

  • @subhamacharya4472
    @subhamacharya4472 Рік тому

    Hi Shreyansh , very useful video . But can you share the sequence diagram for all the 5 caching strategies as it will help to revise whenever needed only by seeing the sequence diagrams 😀

    • @ConceptandCoding
      @ConceptandCoding  Рік тому

      Yes i have shared it on LinkedIn too, i will upload on gitlab and share the link by today buddy.
      Thanks for reminding, i forgot to push the diagram on gitlab

  • @vennamurthy
    @vennamurthy Рік тому

    Thank you @Shrayansh Jain

  • @harshagrawal007
    @harshagrawal007 Місяць тому

    Could you please share, or link the video that contains Part 2, cache eviction policies

  • @vikasjoshi8381
    @vikasjoshi8381 Рік тому

    Thanks. very informative. One question. should'nt cache take responsibility for updating database in write-through strategy?

    • @ConceptandCoding
      @ConceptandCoding  11 місяців тому

      Depends, if cache library do not support this, even application can write into DB after writing into the cache

    • @vikasjoshi8381
      @vikasjoshi8381 11 місяців тому

      @@ConceptandCoding makes sense. In that case we need to take care is of rollbacking cache updations if DB related exception occurs. Thanks a lot.

    • @ConceptandCoding
      @ConceptandCoding  11 місяців тому

      @@vikasjoshi8381 exactly.

  • @vivekchourasiya1875
    @vivekchourasiya1875 Рік тому +1

    Bhut acha video tha theory samaj m aagya but sir isko practical me kaise select krenge aur kya kya krna pdega uska bhi detail btae

    • @ConceptandCoding
      @ConceptandCoding  Рік тому

      I have shared the pros and cons right. That will help you to select which strategy to use.

  • @ehtashammazhar3518
    @ehtashammazhar3518 6 місяців тому

    Hey Shreyansh… in write around if a put/ patch request invalidate the data and same time db goes down and then get request comes so what is the use of this stale data ?

    • @ConceptandCoding
      @ConceptandCoding  6 місяців тому +1

      This stale data is of no use, it will be removed from the cache after its TTL.
      But in real world scenario, if DB goes down, again the read should be success from the replicas.
      Now this open ups one more scenario, lets understand that:
      - Put request has make the Cache Invalidate and updated the DB with Version 2
      - Before the Sync up happens between other replicas, lets say DB got down
      - Read is coming, and it will read the data from DB (since mail DB is down, so replica will fulfill the request and since sync up was not happened, lets say replica has Version 1)
      So GET call should not put this Version1 in the Cache. Else we will put stale data in the cache. So that scenario need to be handled too.
      Only read it but in cache we should not put in that scenario.

    • @ehtashammazhar3518
      @ehtashammazhar3518 6 місяців тому

      @@ConceptandCoding thanks for explanation. highly appreciate your service for the community. keep it up man.

  • @ritveak
    @ritveak Рік тому

    In write through cache we write everything in cache and the DB in a 2phase commit, meaning cache has all data that DB has.
    Then the cache would be heavy as well, the searchability will take more time !
    Is it good only for small data scenarios?
    Also what's the significance of a cache if the DB and cache have same amount of data?
    Correct me if I am wrong but Does the presence of cache in memory and giving faster access the only pro?

    • @ConceptandCoding
      @ConceptandCoding  Рік тому +2

      Access to cache is fast compared to DB.
      Generally it's a happy scenario that Cache and DB has the same data but sometimes Cache helps to achieve fault tolerant when DB is down.
      Cache is not as big as DB bcoz the TTL of cache is less 3hrs, 10hrs etc depends upon the need.
      Cache searching done based on Key, so fetching the data is faster only.

    • @sdash2023
      @sdash2023 Рік тому +1

      As he correctly explained the older data will be removed, and new data will be added to cache using LRU, LFU or FIFO logics. So cache will not grow as big as db. It depends on the TAT and TTL. Thanks for the question it will help others get the answer.

  • @rahulbharadia9152
    @rahulbharadia9152 5 місяців тому

    Buddy which software u have used in this for teaching ??

  • @ayush24jai
    @ayush24jai Рік тому

    Sir from where u learnt all these ?

    • @ConceptandCoding
      @ConceptandCoding  Рік тому +1

      8 saal ka exp hogaya hai, kaafi to projects mein implement karne ke liye analysis karein hue hai.

  • @anirbunt
    @anirbunt Місяць тому

    How is Write back Cache fault tolerant,
    a) what if there is down time in messaging service where server can't push the message to queue?
    b) What if the server crashes before sending the status to queue while it has already sent a successfull response.

    • @girishanker3796
      @girishanker3796 27 днів тому

      In distributed systems, we will be having multiple instances of the application running on different servers. So in order for the systems to be highly available you can go for multi node architecture.

  • @shubhamkumar6383
    @shubhamkumar6383 Рік тому

    which type of cache we can use in a multiplayer game where user answer the question and they earn coins and user scale is very large ?

    • @ConceptandCoding
      @ConceptandCoding  Рік тому +1

      It's not like that Shubham, we have to collect more requirements like how much get call we expect?, how much write call we expect? is there a case where same data can be requested?
      Is less Latency required? When DB goes down, still read and write should work?
      Then we can choose any strategy