Caching Pitfalls Every Developer Should Know

  Рет қаралды 105,650

ByteByteGo

ByteByteGo

2 ай бұрын

Get a Free System Design PDF with 158 pages by subscribing to our weekly newsletter: bit.ly/bytebytegoytTopic
Animation tools: Adobe Illustrator and After Effects.
Checkout our bestselling System Design Interview books:
Volume 1: amzn.to/3Ou7gkd
Volume 2: amzn.to/3HqGozy
The digital version of System Design Interview books: bit.ly/3mlDSk9
ABOUT US:
Covering topics and trends in large-scale system design, from the authors of the best-selling System Design Interview series.

Пікірлер: 58
@IceQub3
@IceQub3 2 ай бұрын
Cache invalidation is the elephant in the room
@dave6012
@dave6012 Ай бұрын
All I know is there are 2 hard things about programming: - naming things - cache invalidation - off-by-one errors
@ANONAAAAAAAAA
@ANONAAAAAAAAA 2 ай бұрын
The most important knowledge about caching is: don't cache unless it's absolutely necessary. Also, database in conjunction with read-replicas can be much more resilient and performant than your homebrew crappy caching mechanism. Caching is final resort, after you've tried everything you can do with database, for example, tuning queries, adding indexes etc.
@build-your-own-x
@build-your-own-x 2 ай бұрын
this should be the first lesson in every caching learning resource.
@RodrigoVillarreal
@RodrigoVillarreal 2 ай бұрын
This only applies if we are doing simple selects / batch data. Read replicas don't solve issues like time consuming queries (expensive joins / aggregations / etc). Of course, you clearly specified: "Unless it's absolutely necessary" :)
@Osono2diWorld
@Osono2diWorld 2 ай бұрын
You’re not building a scalable system without caching.
@wilfredv1930
@wilfredv1930 Ай бұрын
there should be a pretty deep evaluation to understand if caching is necessary or not. failing in that would lead to disaster sooner or later
@michaelkhalsa
@michaelkhalsa 2 ай бұрын
Caches work well in tandem with claims, that is some data should never be cached, but rather claimed by a user during the editing process, with ability for another user to revoke the claim. Saves always check claim status first. Multi level cache invalidating is important. For example, products returned for a catalog can use a product cache with a polled cache invalidating process. Yet, for display on a product detail page a quick check of a timestamp is done which is reset if any of the various product tables are updated by a trigger. Thus a quick scaler db query ensures the cache is valid, which also helps protect the cache itself from becoming stale. This can be taken even further with a dedicated timestamp table for complex product information. This approach dramatically improves performance, always guaranteeing valid data on a detail page, while keeping catalogs valid within the timespan of the cache manager for polling a cache invalidation table for changes.
@Kingside88
@Kingside88 2 ай бұрын
I really appreciate your video. They are so high quality with the best explanation. Can you please make a video of what is the best strategy for using a relational database like Microsoft SQL or what else together with elastic search. How to keep them synchronized? Thank you in advance
@maxvaessen
@maxvaessen 2 ай бұрын
Very useful! Thank you ❤
@rogers.1228
@rogers.1228 2 ай бұрын
Use jitter to the TTL to reduce cache avalanche and many related issues
@BigHalfSteps
@BigHalfSteps 2 ай бұрын
I'm surprised that there is no mention of a easy solution (albeit there might still be an issue when starting from a cold cache) for a Avalanche/Stampede: Just use different caching times. That should somewhat alleviate when the database is hit with multiple requests. But in essence, only cache what is necessary.
@mailbrn78
@mailbrn78 2 ай бұрын
Thanks for the insights on cache management. Could you plz suggest keys in cache need encryption? What should be the key flush time.
@toxicitysocks
@toxicitysocks 2 ай бұрын
Would love to see you tackle cache consistency too: what happens when the database write succeeds but the cache write fails? Or if the database is written concurrently to 2 different values but the last write to the database was value a, while the last write to the cache was value b? Now the cache is forever inconsistent.
@wesamadel3612
@wesamadel3612 2 ай бұрын
remove cache entry on every update
@toxicitysocks
@toxicitysocks 2 ай бұрын
@@wesamadel3612 sure, but what if there’s a network failure getting to the cache after you do the update in the db?
@eNITH24a
@eNITH24a 2 ай бұрын
Search the dual write problem. Using some form of event driven system, like a CDC (change data capture) in your db to write to an apache kafka stream. That way, the log is persisted in the queue. Say, the cache goes down, the event will still be in the queue and can be read when the cache is back up. However, I'm not sure what you would use to source data from kafka to redis.
@toxicitysocks
@toxicitysocks 2 ай бұрын
@@eNITH24a yeah, that’s the best solution I’m aware of. I just wonder if there’s any other way besides CDC or two phase commit. As for getting data from Kafka to redis, you could write a simple consumer service that reads the events and writes to redis.
@eNITH24a
@eNITH24a 2 ай бұрын
@@toxicitysocks I figured you could write a consumer service, but then doesn't that introduce another source of failure? Or I guess it's a lower source of failure if all it does is push to redis from Kafka.
@simonbernard4216
@simonbernard4216 2 ай бұрын
at 0:27 on the left diagram, shouldn't the process order be : 1. Data request 2. Data response (no cached data) 3. Read original 4. Copy cache
@vladyslavlen9490
@vladyslavlen9490 2 ай бұрын
What if we add some kind of jitter for the key TTL, so we minimize the probability of having them expired at the same time?
@eduardokuroda8586
@eduardokuroda8586 2 ай бұрын
to use a bloomfilter it sounds like easy, but it can't delete element yeah? will it need to refresh the bloomfilter after something to ignore deleted itens?
@parthi2929
@parthi2929 2 ай бұрын
If something creates traffic, have a traffic signal, ok.. a lock here... regulate.. If something creates traffic, have multiple systems (web server/cache server etc) to handle it.. If something can fail, have redundant backups of THAT.. this applies to anything.. also.. to know if cache could fail in DB caz relevant answer not in DB, note down that before in some way..
@kazama81
@kazama81 2 ай бұрын
Question: What's the point of a cache server? Why the server itself / webserver is not doing the caching? If caching is supposed to be for fast retrieval, if we store it in a different server, won't the network call take more time than querying a db in the first place?
@devid3085
@devid3085 2 ай бұрын
At 3:58 the "find key" arrow has a typo and it should be (3) instead of (4)
@raj_kundalia
@raj_kundalia 2 ай бұрын
thank you!
@PranaySoniKumar
@PranaySoniKumar 2 ай бұрын
Can't we use request collapsing to prevent stampede? As it maily due to expired cache entry and multiple requests are trying to access the same resource?
@micahpezdirtz8196
@micahpezdirtz8196 2 ай бұрын
How can there be less than 1m subscribers to your channel? You have the best explanations
@nixjavi7220
@nixjavi7220 2 ай бұрын
Amazing vídeos
@NemiroIlia
@NemiroIlia 2 ай бұрын
2:33 a hidden smiling gem at the bottom right
@user-je9fw2rl5s
@user-je9fw2rl5s 2 ай бұрын
What use to for presentation and demonstration, please ?
@ANONAAAAAAAAA
@ANONAAAAAAAAA 2 ай бұрын
The scariest story I've head about caching is, pages containing user's private info are cached on CDN, then they forgot to include session id in the cache keys...
@StoCoBoLoMC
@StoCoBoLoMC 2 ай бұрын
What is CDN? Why can't info be cached on it?
@venberd
@venberd 2 ай бұрын
Content Delivery network - Vendor operated nodes geographically located closer to user. Very little isolation guaranteed. Don’t want to put your users data permanently there
@chrishabgood8900
@chrishabgood8900 2 ай бұрын
Could the db invalidate the cache?
@krazeemonkee
@krazeemonkee 2 ай бұрын
“cache me outside, how bout dat”
@rizthetechie
@rizthetechie 2 ай бұрын
Just wondering if proactively cache the pages on expiry again, why put expiration ?
@TyllerJorEl
@TyllerJorEl 2 ай бұрын
data may change; also, if delete-key events randomly go missing (it could happen for a myriad of reasons), stale data could pile up forever and fill up the memory
@titogorla
@titogorla 2 ай бұрын
love it
@zixuanzhao6043
@zixuanzhao6043 Ай бұрын
what about consistency
@MrSofazocker
@MrSofazocker 2 ай бұрын
Hear me out. What if you don't ever hit the DB, but the Cache either halts or returns a null value for all requests, and singularly fetches the data from the DB. Then answers all suspended requests!?
@gus473
@gus473 2 ай бұрын
Comment for algorithm, thank you! 😎✌️
@vadymk759
@vadymk759 2 ай бұрын
There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton
@uchuuowl7605
@uchuuowl7605 Ай бұрын
GOLD
@franklinoladipo2343
@franklinoladipo2343 2 ай бұрын
Was thinking he would talk about Cache Invalidation
@rishiraj2548
@rishiraj2548 2 ай бұрын
👍
@jerichaux9219
@jerichaux9219 2 ай бұрын
Obligatory zeroth.
@aruneshprabu7925
@aruneshprabu7925 2 ай бұрын
❤❤❤❤
@navinmittal4809
@navinmittal4809 2 ай бұрын
In summary, I think he explained 3 scenarios when there's a huge load: cache miss on single key (stampede), non-existent key (penetration), bulk cache miss on multiple/all keys (avalanche).
@chologhuribangladesh7792
@chologhuribangladesh7792 2 ай бұрын
Most people do not care about caching. They cache whatever they want.
@burhanudinyahya
@burhanudinyahya 2 ай бұрын
😂😂😂
@atifadib
@atifadib 2 ай бұрын
Cache Crash
@wishmeheaven
@wishmeheaven 24 күн бұрын
Is this video sponsored by Redis?
@ChuckNorris-lf6vo
@ChuckNorris-lf6vo 2 ай бұрын
Hi bro can you explain complex solutions with a little bit more LIFE in the voice? Like give it MEANING give it energy. Solutions are important bro. Be more alive so it is crystal clear, why a certain solution is being done even if it is very complex. Thank you. And make the video longer if you have to but make it the best god damn explanation of the problem. Thanks.
@Geza_Molnar_
@Geza_Molnar_ 2 ай бұрын
I'd like to watch short (beginner : 5-15 mins) - medium (advanced : 10-25 mins) - long (professional : 30-60 mins roughly) videos about the topics which are on the channel. I'm fine with the content, that's already enough 'energy' for me. I have my motivation to listen, to think about that, to hit the back button when I need repetition or more time for thinking and understanding (no need for more 'life in the voice' for me to push me).
@BenjaminMeasures
@BenjaminMeasures 2 ай бұрын
There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton
Top 5 Most-Used Deployment Strategies
10:00
ByteByteGo
Рет қаралды 238 М.
Consistent Hashing | Algorithms You Should Know #1
8:04
ByteByteGo
Рет қаралды 279 М.
Omega Boy Past 3 #funny #viral #comedy
00:22
CRAZY GREAPA
Рет қаралды 33 МЛН
it takes two to tango 💃🏻🕺🏻
00:18
Zach King
Рет қаралды 30 МЛН
MOM TURNED THE NOODLES PINK😱
00:31
JULI_PROETO
Рет қаралды 12 МЛН
Top 7 Ways to 10x Your API Performance
6:05
ByteByteGo
Рет қаралды 304 М.
Top 12 Tips For API Security
9:47
ByteByteGo
Рет қаралды 65 М.
Devlog #11- How to make your DB fast by using Caching
8:34
Superthread
Рет қаралды 12 М.
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 958 М.
Top 5 Redis Use Cases
6:28
ByteByteGo
Рет қаралды 162 М.
The Secret Sauce Behind NoSQL: LSM Tree
7:35
ByteByteGo
Рет қаралды 189 М.
Back-Of-The-Envelope Estimation / Capacity Planning
8:32
ByteByteGo
Рет қаралды 85 М.
Design Twitter - System Design Interview
26:16
NeetCode
Рет қаралды 449 М.
ПК с Авито за 3000р
0:58
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,5 МЛН
#miniphone
0:18
Miniphone
Рет қаралды 11 МЛН
3D printed Nintendo Switch Game Carousel
0:14
Bambu Lab
Рет қаралды 4,7 МЛН
iPhone 15 Pro vs Samsung s24🤣 #shorts
0:10
Tech Tonics
Рет қаралды 9 МЛН
iphone fold ? #spongebob #spongebobsquarepants
0:15
Si pamer 😏
Рет қаралды 228 М.
AMD больше не конкурент для Intel
0:57
ITMania - Сборка ПК
Рет қаралды 509 М.