0

This is a problem related to a typical e-commerce requirement.
I am using ElasticSearch for all the below use cases.
I am confused about whether or not to use MongoDB for the sorting part.
I have the data in the following format:

Product JSON:

{
  "name": "String",
  "description": "String",
  "characteristics": [
    {
      "name": "Brand",
      "value": "Apple"
    },
    {
      "name": "Color",
      "value": "Red"
    },
    {
      "name": "Storage",
      "value": "64GB"
    },
    {
      "name": "stockStatus",
      "value": "IN_STOCK"
    }
  ],
  "prices": [
    {
      "priceAmount": 100000,
      "discounts": [
        {
          "discountAmount": 300,
          "conditions": [
            {
              "name": "primeCustomer",
              "value": "true"
            },
            {
              "name": "oldCustomer",
              "value": "true"
            }
          ]
        },
        {
          "discountAmount": 500,
          "conditions": [
            {
              "name": "deviceType",
              "value": "premium"
            }
          ]
        }
      ]
    }
  ]
}

I want to

  1. Search based on name or description.
  2. Filter based on characteristic name and value.
  3. Sort based on the discounted price.
  4. Pagination
  5. Filter products lying at a particular price(discounted) range.

Multiple discounts can be applicable at the same time - like in the above example, the customer is prime+old as well the device is premium. I want to evaluate the conditions on runtime based on the input parameters and then sort the results based on the final discounted price.

I will definitely run benchmarks for both ES and MongoDB but before that, I would like to know are there any recommendations for this type of scenario?

I have to operate on millions of product documents.

Right now, I precompute all the possible combinations of the conditions and then create a single price document for each combination to avoid any calculations on the runtime. But the combinations are too much given the conditions are increasing every day with new business requirements.

5
  • This is were a relational database shines. Also consider precomputing when the product/discount changes not when the search is happening. Commented Nov 21, 2019 at 1:18
  • I am not confident that the relational databases will be able to handle high load and search efficiently. This is the major challenge that if some discount definition changes, then all the products need to be updated which is not possible in real-time. Commented Nov 21, 2019 at 6:57
  • That is why discounts should be defined in advance, so that they can be precomputed, instead of on the fly. Billing should always re-derive the cost from first principles though. The precomputed value is for search only. Commented Nov 21, 2019 at 22:45
  • discounts are pre-defined but when to apply which discount will be decided on run-time Commented Nov 22, 2019 at 7:46
  • Yes that is pretty obvious, as the discounts are contextual by your own definition. Your choices are to: calculate those values on the fly for every search, precompute them offline in advance for each contextual combination, not provide a search based on discounted price. Point this out to the business. They will either pay for the expanded computational resources, or they will have to compromise on discount complexity/sacrifice discounted searching. Commented Nov 23, 2019 at 0:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.