I am developing a simple web server that runs on a raspberry pi zero and lights up an LED when a request is received on the POST route (with a given color, intensity, blink timing and other informations contained in the request data) and shuts it down when a request is received on the DELETE route.
I wanted to have a sort of backup of the requests i do to the server so that they can be "redone" (in whatever order) when the server restarts so that the LEDs will turn on without having to redo all of them by hand.
Right now (since it was the easiest and fasted way for me to do it as a proof of concept) every time i make a POST request i save the color in a dict using as key the serial of the LED and then write the dict to a json file.
When i receive a DELETE request i read the file, delete the entry and write it again with the other information that it may contain (if more than one LED was connected), if the server loses power or gets shut down and restarts it reads the file and restores the LEDs statuses.
I was wondering what would be the best way to have a system like this (either using a file, DB or other possible solutions) in a way that would use the lowest amount of RAM possible since I already have other services running on the rpi that use quite a bit of it.
Depending on how many LEDs there are it sounds like what you are doing will be a JSON file of only a few bytes, right?  There are ways you could compress that, but unless you have a huge number of LEDs I doubt it will be a significant saving compared to everything else.
Saving data using less RAM possible