asynchronous data update

Hi,
We are developing an e-commerce site in ROR. We have a table which
stores the prices of our products. To save on repeated database
queries, we read the table and store it in memory.

As the admin can change the prices through the management console we
are facing the problem of updating the in-memory data. We are running
the application on mutiple servers,with multiple instances of mongrels
serving the requests. Thus all the mongrels have their own copy of the
in-memory data.

Now we think there are few issues

1. We would need to update it on every mongrel.
2. We don't want the scene where there are different servers/mongrels
have different version of the pricing.
3. We are hoping there is some way where we won't need to shut down
the whole site !

We tried to use the SEE-SAW. but i think it doesn't take the business
of mongrels into account. Thus if one of the mongrels is serving a
long request while it receives the restart request, things go wrong
and the mongrel dies in the end.

We have been discussing this issue and come up with the following
solution.

1. Copy the prices to the user's session (which is anyway read every
time) and use that to create the shopping cart etc.
2. Update the each of the mongrels through an http request/ web
service.

This way the user will see only one version of the prices throughout
his transaction.
But this again has some problem. What if a user somehow keeps his
session to be alive for a very long duration ( if he knows the pending
price update.) Even though we don't keep persistent shopping cart, a
malicious user can, though a script, keep his session alive for days/
weeks or even months and thus use the old prices. We did use this
trick for our online submission of assignments in college :wink:
As a last resort we can check the staleness of session prices in the
last checkout step.

We think this is a common problem and every e-commerce site should be
facing this but can't seem to find any published solution. We are
hoping some can put some light or point us in the right direction. Any
help would be appreciated

A.K

a.k wrote:

We are developing an e-commerce site in ROR. We have a table which
stores the prices of our products. To save on repeated database
queries, we read the table and store it in memory.

As the admin can change the prices through the management console we
are facing the problem of updating the in-memory data. We are running
the application on mutiple servers,with multiple instances of mongrels
serving the requests. Thus all the mongrels have their own copy of the
in-memory data.
...
2. Update the each of the mongrels through an http request/ web
service.

The above is one of the methods I've used. In your case the mongrel
getting the price change update would do a GET of some 'reload_prices'
action on each handler. You can limit the IP addresses able to call
this action.

Another method I've used is Ruby mmap. This allows no-overhead
sharing of a Ruby string between a set of mongrels on a single
server. This only really comes into its own when the changes you
want to propagate are small but frequent.