At the moment I’m receiving data from sensors and I’ only keeping latest version in RDS, however I would need to store all historical data somewhere for future analysis.
What would you recommend for storing them? they would be rarely accessed, as in 99.99% of cases only latest data is needed.
I was thinking of saving it to S3, but I’ worried that request cost will get out of hand.
Storing many small objects in S3 is no good. However, if you aggregate the data and store it in chunks in S3, that’s better. Something like that can be accomplished with Kinesis. Bonus points for storing it in a sane format which will allow you to use a service like Athena to query it directly from S3 after the fact.
Another option may be DynamoDB. Whether or not DDB is suitable will depend entirely on the details and requirements of your application, but it’s always worth checking out as a solution.
There are other database solutions and services to look at, but these are the first things that come to mind.
There are lots of options. As people have said, timestream is good. Is the data in a known format, or is this legacy IOT with all kinds of weird things?
You could also save them to an S3 bucket, then run a lambda overnight that gzips them up and moves them to another bucket. You could then use Athena to query.
You could also get fancy and use firehose to analyze on the fly.
I mean, is it one sensor updating once a week for a personal project or is it one hundred fifty million sensors updating once a second in a mission critical app?
It sounds like Timestream is perfect for your use case - it automatically moves your data to more inexpensive magnetic storage as it gets older, and can also automatically delete data older than a certain age if you like.
I’d agree with /u/Nater5000 that Kinesis seems to be a good fit for this sort of thing, IF there’s a large enough volume of data to make it worth it.
Since you’re already storing the data in RDS, I’d KISS-principle it and do the following:
Store more than just “latest” in RDS, keep a history.
Have a horizon after which data is batch-offloaded to S3 on some convenient regular schedule, and then deleted (well… verify the S3 file first, maybe just mark the data for deletion and clean it up at a further-distant horizon, etc).
But it all depends on how much data you’re talking about, etc. If it were my setup I’d try and stick with RDS as long as possible; using tricks like partitioning to split up the data in the tables (for example, partition by day or hour; so your queries for “current” data remain fast, and the queries to “archive” data can operate on distinct separate partitions from “current”) if the amount of data is truly massive.
For a very specific example of how I’d do this (off the top of my head because I’m bored, assuming all of this in mysql (just because it’s what I’m familiar with), but probably postgres has equivalents because it’s good stuff) here’s what I’d do:
RDS table recording all data with a timestamp index (at least a timestamp index, others depending on queries of course)
partition said table by day from timestamp (ensuring regular queries to fetch “current” data only read from the “current” partition)
create a scheduled event to regularly select into outfile s3 the entire contents of some previous partition, and upon successfully doing so, delete all data from that partition.
That way you don’t really need any more infrastructure than your existing RDS setup; and the S3 bucket. No ec2 nodes or lambdas or kinesis to worry about.
Using Kinesis and then saving chunks in S3, does sound like a good solution. I’m currently thinking between that or using Timestream as other people in thread suggested.
If you’re going to dump it to S3, take a look at Kinesis Firehose, as it handles the chunking and writing to S3 for you, and can even write it as a compressed parquet format for you.
Second this. SNS to Firehose is super nice. A heads up, SNS FIFO to Firehose doesn’t work. (I’d really like to know why the SNS FIFO/Firehose integration doesn’t work)…
If you willing to use another service I would take a look at influxdb cloud. I used this often for exactly the same purpose and it’s much cheaper than timestream and does not have some of the drawbacks that timestream has.