Database Design for storing Key-Value Tags per Item

48 views Asked by At

I want to build an online shop where the products don't follow a specific schema, so the attributes can be quite different for each product. My idea is to allow the sellers to define custom tags with values (like key-value pairs) for their products, which I can analyze later to provide the most used tags per product category as filters. I read a lot about this topic online, but in most cases, only simple tags (without values) are discussed. In this case, I would just store the tags as JSON in an additional field in my postgres database. But I'm not sure if that's the best solution with my key-value pairs. For example, the key for a product could be something like "weight", and I want to provide filters for it, like "weight" > 100 AND "weight" < 1000.

I'm trying to find answers to the following questions:

  • What would be the best data structure for my case?
  • How can I handle data types? One seller could type "1000" for the weight, another one could type "1000kg" or "1 ton". I'm not sure how I can handle this while filtering.
  • Are there any real-life examples for a scenario like this? Amazon does not provide that much filters, and most other shops are designed for one specific type of product and do not face this problem.
0

There are 0 answers