[Fixed]-Keeping state and sharing common processing between django requests

1👍

You should use a persistent central store, so even if you have more than one server with a load balancer, all will access the same flag. If you set attributes to classes at runtime, one server will see the flag, but if the node balancer sends the next request to another server – it will not.

The specific solution is based on the size of the data, frequency of updates, expected traffic, etc, Generally fetching a single flag from the DB is fast, so you should consider if it’s worth for you to install and manage a central cache. If you do use central cache, file based cache is easy, then it becomes more complicated. Maybe DB will do?
You can make it even faster:

  1. The flag table with few indexed integer columns, so each DB page covers a lot of index rows

  2. Query the DB with direct SQL, just to get the flag with MySQLDB, and save the overhead of django objects and models

  3. Use a separate DB from all others django tables.

Leave a comment