D
D
Dmitri Sinitsa2015-03-20 23:09:37
Redis
Dmitri Sinitsa, 2015-03-20 23:09:37

Pre-calculation of prices - how to cache?

Hello.
The bottom line is that there is a service that rents out premises (there are about ~ 50,000 of them now).
The client can rent each room for the period of days that he chooses (there is a calendar for this - that is, for each day the owner of the room can set different prices at his discretion).
The whole essence of the price calculation: p = f( check_in, check_out, x ), where check_in, check_out are the check-in and check-out dates, respectively,
and x is a number from 1 to 10.
Just recently we finished connecting fairly complex systems discounts and additional services, and now the calculation of prices as a process has become very non-trivial - I won’t even describe these wilds, I’ll just say that everything is sad.
And then there was a need to make a sorting system for the finalprice on the search page.
And here I don’t know what to do - I won’t be able to describe all these processes in one MySQL query (it used to be like that). Yes, even if it could, it would be slow and inefficient. Moreover, prices are not updated often - there is no special point in counting them every time.
There was an idea to calculate prices for, say, a year ahead for all premises.
That is, recalculate all possible combinations (check_in, check_out, x), cache, and invalidate the keys if necessary.
But then the question arises - is it real at all? I did a quick calculation on a piece of paper, and it turned out that it would take about
33,580,500,000 keys if stored in a key-value store: 366 * 367 / 2 * 10 * 50,000.
And where can you store so much?
Or are there other, more efficient solutions? Moreover, the memory is not rubber.
Thanks in advance for your replies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2015-05-05
@andreyvlru

Maybe an approximate sorting will be enough for you.
Calculate some simplified price index for each object and sort by it.
You can complicate and make the price index also dependent on the rental period and the week-month of the year.
The task is in many ways similar to what many ticket search engines do, I wonder how they do it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question