I have data which is a document. Each document can have 1 to many paragraphs.
20 million documents. 200 million paragraphs.
Since in the average case I cannot store the entire document as a single record. I plan to store each paragraph as a record.
The partition key will be document id and the sort key will be paragraph number.
The initial full load of the dataset will be simple but when a document changes and I need to perform updates it gets complicated.
When a document changes. I plan to delete all records that have document Id. Then insert all the records (paragraphs)
Obviously this has the downside of the data for that document disappearing momentarily and I can think of a few creative solutions to solve that but don’t seem like it’s worth the hassle.
As a novice to dynamo I want to make sure I am not missing something basic here. Thanks!
Howdy! Can you elaborate on your requirements? What file formats are these documents? What are the use cases for these documents - why are you storing them in the first place and how are they being used?
Is there a particular reason for wanting to use DynamoDB? Without knowing more, S3 and Athena sounds like a better fit for storing and querying the data you describe.
I’d put the actual document bytes/text in S3, with corresponding rows in DynamoDB, and (assuming these documents are ‘viewed’ in singular requests) have lambda generate and deliver pre-signed URLs to your front-end caller (who has, of course, been assigned a valid IAM role with the appropriate permissions to request a pre-signed URL).
That said. A lot of this depends on your use case (and what your front-end/consumer for these documents looks like). I’m assuming these will be listed in a grid in a website or something.
Well the data will be stored as Apache Hudi prior to loading to dynamo so an Athena table is possible but the application access pattern is quick guid based retrieval
The data is computed on an EMR cluster as part of a spark streaming application. Data will be saved to Apache Hudi. This will then be loaded to dynamo so the application team can quickly retrieve the paragraphs and execute a few lambdas. The retrieval has to be extremely fast
The paragraphs are actually paragraph embeddings stored as 512 vector. When a customer executes our workflow. Their input runs through various steps, eventually arriving at needing about 1k random documents (all the paragraph vectors). All of these steps need to execute in a reasonable time for the user. For this portion lookups of all documents need to occur in under a few seconds
The use case is not to display text on a website. It’s to run a machine learning algorithm. A customer will execute this by inputting numerous data which will launch our pipeline. During the entire pipeline there will be a portion that will identify 1-10k documents as candidates. We need to fetch all of the candidate documents paragraphs. So we need random access lookup of many documents quickly
So if you need full text indexing, you probably want elastic search (open search), and if you’re not doing that, then you don’t care about paragraph content in lookups- so absolutely use dynamo to reference the data, but store it in s3 and either return the whole document (caching with cloud front could be useful) or read the doc contents and return the text string. All the chained dynamo records sound messy- it’s better used as an index than a segmented blob store.
Don’t need text indexing because we are actually storing vectors of the paragraph on dynamo not the actual text. The lookup (lambdas) will take the paragraph content and compare that to other user inputted paragraphs (sort of).
Agree the flattened data in dynamo to work around size is sort of a nightmare and part of the reason I asked the question. My architects haven’t presented me with better options.
Can you explain what you mean by use dynamo to reference the data? Does that mean have like a location column?
I would love to be able to just store the document.
Prior to the data being saved to dynamo it’s stored as an entire document in Apache Hudi (basically parquet)
Hi I’ll read more into it tomorrow but I thought I read somewhere that max items per transaction was 20 which doesn’t fit my use case. Or maybe it was max size (which equates to 20 of my items)
25 actions - but yeah, if you need more than that then it wouldn’t work for you without splitting up the transactions which kind of defeats the purpose.
Are you able to write the updated document with a new document id, update the system that generates the 1k random documents to point to that new id and then delete the old one?
Lambda allows you to run any scripting transformations (for example), kick of any SSM automation documents that can load data into tables. All of the above can be triggered with EventBridge.