5 ms·
I wonder if anyone's gone the next step and written updates to the caches directly, leaving out the database write from the critical path.
by alexandros 17y ago
I wonder if anyone's gone the next step and written updates to the caches directly, leaving out the database write from the critical path.
- DrewHintz 17y agoAnd then what happens when the server with your cache dies? :)
- axod 17y agoUpdate the cache instantly (critical path), update the db lazily queued?
- laut 17y agoDo you mean that when you get an update, you both write to the database and perform an update in the cache? If so, you would want it to be a transaction so that the cache and database is not out of sync. Maybe a write cache, like on hard drives with write back caching. If you first wrote the update to a cache (queue of updates). Then it would be written to both the cache (cached html for instance) and database in one transaction. But I think it sounds like more trouble than it's worth.
- alexandros 17y agotransactions are unnecessary, unless you are looking for 100% consistency between cache and database at all times. Usually this is not the case and if it is, you will have extremely serious problems scaling. All i'm saying is: If you have an update that you know will invalidate some cached pages, why invalidate them and then rerender them from the database once the update is commited instead of updating them directly. and lazy queueing the update, taking the load of the database (less pressure to commit instantly, and less reads). In the facebook inbox example, you know that a new message to the user will increase their message count by one. Just update the cache directly with this new info. When/if it explodes, by all means, rerender everything.
- jasonkester 17y agoWe do this for the Twiddla sandboxes. The key is that you have to be prepared for everything to evaporate if the server cycles its memory for whatever reason. In this specific case, we toss everything out of the sandboxes every 5 minutes & reset them anyway, so it's no great tragedy if they clean up after themselves from time to time. For something with a ton of low-priority edits (like HN or Reddit where nobody sues you if their vote goes away), you could certainly get away with caching updates and only saving them out every once in a while.