-2

I am midway through my software development project in Node.js and have encountered a fork in the road. I need to create a "database" or a JSON file, that will automatically delete an entry after it has been in for X amount of seconds. An entry is simply just a random string.

Should I use JSON and write an asynchronous function that runs in the background? Should I use some kind of light database?

  • 3
    Redis has key a expiration feature built-in. – Mat Oct 20 '19 at 5:18
  • 1
    @Mat REDIS came to my mind immediately, too. You should make this into a (preferably somewhat more detailed) answer. – Hans-Martin Mosner Oct 20 '19 at 5:36
  • Do you really need to physically delete the entry in real time? You could just give it another field-- an expiration timestamp-- and set that when you create the entry. The code that reads the database would check the timestamp and ignore any entries with an expiration timestamp that is less than the current system clock. There would be no need to physically delete the entry, unless space is a concern, in which case you could have a lazy process (perhaps to run off hours) to clean up entries that had already expired. – John Wu Oct 22 '19 at 0:27
1

I would encourage you to delay and defer making this design decision for as long as you can.

Make this decision early and it can weave it's way into much of your code and become entrenched. Better to push it out to a plugin and let the plugin decide which it's going to use. All the rest of your code cares about is that it can persist. How isn't important. Not knowing how is very valuable. It means you can change your mind later easily by changing the plugin, not be rewriting large swaths of code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.