Search code examples
databaserelationalaerospike

Aerospike: Something like relatation


I should make a site price comparisons in pure aerospike, then: products, combination products (a cpu related with some motherboards) and stores. ù The products should relate with the stores, for example a product is related to three stores and each store has a different price.

Aerospike can help me in this?

I thought I might make the relationship bins, but I do not know if it is a good idea suggestions to solve the problem?


Solution

  • You can model many-to-one relationships that otherwise would be spread on two tables in a single aerospike set using the complex types list and map. So a combination product can have a 'components' bin which is a list of map objects, each of them a product. Or you can have 'components' be a list of product IDs then batch-read those products based on the IDs in the list.

    However, you can also model many-to-many relationships in a similar way to an RDBMS, with an intersection table. You do not have JOIN, but you can perform separate queries and rely on the fact that aerospike key-value and batch operations are far faster than an RDBMS.

    So for example you can have a store_products intersection table where you can keep an ID of the store and of the product. You build a secondary index on both the store ID and the product ID, and this allows you to do queries. If you're looking for all the stores carrying a certain product you do a query, then fetch the store objects from the store table. If you're looking for all the products in a store you query withe a where store_id=x and then do a batch-read for those products.

    I hope this answers your question.