3 ms·
If it'a controlled restart, you can dump your memory onto a file when shutting down, then reload the dump when you restart. If it's a crash, yes, you will lose
by curtisblaine 2y ago
If it'a controlled restart, you can dump your memory onto a file when shutting down, then reload the dump when you restart. If it's a crash, yes, you will lose everything. Or you can do Append Only File persistence like Redis, in which case you won't lose anything in each case.
- thih9 2y ago> dump your memory onto a file when shutting down, then reload the dump when you restart To me this sounds like building your own db but worse.
- curtisblaine 2y agoAgree for the dump idea, but AOF persistence is quite easy to do (literally open a file and append). Of course you'll have to choose the right data structures in memory, but that can be ad hoc to your app, so considerably less complex than a general purpose database. The only problem is when you go out of memory, but if you have an eviction strategy (i.e. a 24 hours life per post), you don't need to scale for a long time.
- thih9 2y agoWe’d still need code to load the data back, also to continously test that code (or debug in production), plus handle data migrations. There might be more use cases. Using a regular db might be simpler at this point, depending on the project’s setup.
- curtisblaine 2y agoLoading the data back is just reading the log file and applying every record one after the other (ignoring records outside the time horizon). Sure you will need to maintain the code, but it's not as complex as writing a database from scratch, as you suggested.