by FpUser · 4y ago · 0 comments
Upon startup all data (except couple of giant tables) is sucked from DB into RAM into highly efficient data structures hence most reading requests are handled in microseconds. Those 2 giant tables are loaded into the same structs but partially. This is usually enough as RAM keeps last few years worth of data and requests that need something older come just couple of times per month. Only writes touch the database and immediately reflected in RAM as well.
This is just an example. I write game like servers as well and those use different approach. Generally I treat each project / product individually.
Sure it will not do Google scale and I do not loose my sleep over it. For most "normal" businesses what I have is way more than enough.
Besides, as I've already said I treat each product individually so my architecture reflects the actual needs and changes accordingly.
BTW for others considering this approach, the DB will do similar things that FpUser is doing in the app layer - keeping hot/recent stuff in memory. But when tail latency and cost really matters this is a good technique.
Not really as the storage data layout and application data layout are different. If I were to use database only relying on it's caching abilities it would lead to complex queries that are definitely way less performant than getting data from in memory structures optimized for this particular application / usage patterns.
On top of that some requests require some relatively complex calculations that again are executed against optimized in memory layout and would suffer greatly if done against the database.
I did some experiments and the difference was very significant.