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

Поділитися
Вставка
  • Опубліковано 13 гру 2024

КОМЕНТАРІ • 59

  • @inayathulla1
    @inayathulla1 2 місяці тому +1

    Amazing explanation. Keep up the good work.

  • @rv0_0
    @rv0_0 Рік тому +6

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

  • @YogaNarasimhaEpuri
    @YogaNarasimhaEpuri Місяць тому +7

    Sir,Have you made part2 video, or is it missing.
    Thankyou for the content

  • @adarshpatel8180
    @adarshpatel8180 Місяць тому +5

    Hi Shreyansh ,
    Part 2 is missing in playlist …

  • @shubhamagarwal1434
    @shubhamagarwal1434 2 місяці тому

    Very well explained.......awsome!!!

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

    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

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

    Bahut Sahi Shreyansh.....Good Job

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

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

  • @harshagrawal007
    @harshagrawal007 6 місяців тому +3

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

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

    Thanks Shreyansh Sir, Loved It.....

  • @sumitbasu5146
    @sumitbasu5146 11 місяців тому +2

    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?

  • @ShashwatShukla-p8h
    @ShashwatShukla-p8h 4 місяці тому +5

    where is caching part 2??

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

    Hi Shreyans, Thanks for the Lecture learnt a lot, Can u plz share the link to the Notes? I tried finding in Community but I see only spring boot and java notes there.

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

    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.

  • @HimanshuKumar-xz5tk
    @HimanshuKumar-xz5tk 3 місяці тому

    Read through cache - Cache Server sits in front of the DB and fetches data from DB and updates the cache in case of Miss.
    Cache Library would mean its the application server that's interacting with the DB

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

    Hi, please upload part 2

  • @hiteshsaini5452
    @hiteshsaini5452 2 місяці тому

    Hi Shreyansh,
    What if in write back strategy db rollbacks due to some inconsistency in data then in this case cache will have ambiguous data and write operation will actually never happen.

  • @ManishTiwari-or8zt
    @ManishTiwari-or8zt 6 місяців тому

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

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

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

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

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

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

      @@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  Рік тому

      @@vikasjoshi8381 exactly.

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

    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  Рік тому +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 Рік тому

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

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

    Can anyone explain clearly why we can have different DS in cache aside while not in read through cache ? Unable to understand Shrayansh's explanation.

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

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

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

    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.

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

  • @HimanshuKumar-xz5tk
    @HimanshuKumar-xz5tk 3 місяці тому

    Cache-Aside Caching Strategy
    Data first read from cache. If present, returned immediately. If not, its fetched from DB, updates the cache and returns
    Pros - Control over what gets cached.
    Cons - Data inconsistency issues. Complexity at application layer
    Read Through Caching Strategy
    Data is read from cache. If present, returned immediately. If not, its fetched from DB by the cache server itself, updated in cache and returned
    Pros - Simple
    Cons - Less control over what gets cached
    Write Around Caching Strategy
    Data is written to the DB. Its updated in the cache, only when read operation is performed
    Pros - Less data inconsistency issues
    Cons - Cache misses since its not always updated
    Write Through Caching Strategy
    Data is written to the DB and cache in same transaction making sure Cache is always consistent with the DB
    Pros - Always consistent data
    Cons - High latency
    Write Back Caching Strategy
    Data is written to Cache and read from Cache. Its updated in DB asynchronously using a queue/scheduler
    Pros - Low latency
    Cons - Chances of data loss

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

    Thank you @Shrayansh Jain

  • @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

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

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

    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 6 місяців тому

      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.

  • @ashishrai4138
    @ashishrai4138 3 дні тому

    Sir please provide notes .

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

    distribute cache need to explain more

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

    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.

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

    👍👍

  • @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

  • @saanikagupta1508
    @saanikagupta1508 4 місяці тому

    You're mixing TTL with TAT

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

    Bhai notes thora sahi se bana diya karo. Kafi ghatiya handwriting rahti hai. Baad mein padhne pe samajh nahi aata ki kya likha hai

    • @ConceptandCoding
      @ConceptandCoding  5 місяців тому +2

      hi, alok i highly encouraged everyone to make self made notes.
      That way, new doubts or question will come, which helps to understand the topic in much better way.
      but feedback taken, will improve the handwriting in all future notes.

  • @DAYANANDRAUT-x2t
    @DAYANANDRAUT-x2t 12 днів тому

    You have unnecessarily extend this video to 37 minutes. this could have been explained in 5 minutes. waste of time.