Ask HN: Keep Last X entries per ID in larger DB
I'm trying to figure out the best solution for the following:
* Daily importing of ~500+ million rows of data, with ~250 million unique ids. * I need to only keep the latest X entries per unique ID. Older entries are discarded after X entries for that id has been achieved. * Monthly will read out the entire dataset for processing
X can be anywhere from 1000 to 3000, it is static over the entire DB just depends on as we determine the best setting. Since I don't access the data more than once a day, or at the end of the month, I would prefer not to pay for storage. There are over a billion unique id's which I can partition by prefix or ranges. Each individual entry per ID is fairly small with only an integer and two decimals stored.
What would you recommend as a data store for this?
Thanks!
7 comments
[ 2.6 ms ] story [ 29.5 ms ] threadInsert a fresh record immediately, since you know it’s recent. Upon successful insert, fire off a queue request to go check on that ID.
If it doesn’t, then set up a DB replica (good idea in any case), do SELECTs on slave, DELETEs on master.
Flat files is my best guess for your data? HDFS
The analysis at end of month is simply give me 100% of the data set chunked up by ID. All analysis is done outside of the system.
Flat files is my thinking right now with S3 and prefixes per partition, I'm not sure on file format, since one thing is with each day's data being able to process and update existing data quickly. Current thought is to load current day's data to Redshift -> unload sorted by id -> process concurrently. With multiple prefixes on S3 I won't hit the rate limits. My main worry is if read in, loading/parsing each file will take too long to be scalable at 250-500 million unique id's per day. I wanted to check here before going down that route to see if anyone had a different recommendation.