I have read several discussions about storing BLOBs in the database vs in an object storage. What I need in addition though is a functionality for querying these BLOBs. The BLOBs will be immutable compressed multi-dimensional arrays that will be 10s of MBs. I mention that, since they are not files that will be served, but rather objects that will be used for some heavy computation outside of the database.
Let me illustrate that by presenting the intended DB schema with a small example, assuming we will be storing them in a relational database.
items
| id | price | company_id |
| -------- | -------------- |-------------- |
| 1 | 5 |1 |
| 2 | 25 |1 |
compute_info
| id | item_id | type | info |
| -------- | -------------- | ---------|--------------|
| 99 | 1 | simple | [large-blob] |
| 231 | 1 | complex | [large-blob] |
| 77 | 2 | simple | [large-blob] |
| 449 | 1 | complex | [large-blob] |
I want to be able to construct complex query that will return only the info for items that match certain criteria, e.g.
SELECT items.id, compute_info.info
FROM items
JOIN compute_info
ON items.id = compute_info.item_id
WHERE items.company_id = 1
AND items.price > 20
AND compute_info.type = simple
Some of the assumptions and other requirements are:
- The query
SELECT COUNT(*) FROM items WHERE company_id = ?
will usually return <1 million. - The BLOB content itself will not be queried.
- There might be multiple concurrent users. There might be 1000s of them in total, but 100s who will actually be reading the BLOBs.
- There are no fixed requirements in terms of database choice or object storage. The goal is to pick the best one that solves this particular problem.
- We can assume a distributed architecture.
The question is what is the proper way to store these BLOBs if performance is critical without introducing too much complexity? The options that I have considered are:
- Store them as BLOBs in the database, just as illustrated in the example. This has the advantage that I could use a JOIN directly.
- The
info
column stores a path to an object storage. This has the problem that we'd need to access a couple of thousand separate files. - Use something like TensorStore given that the application is ML. I don't have any experience with this, but I'd still need efficient random access.
- Some other approach.