Generally, a Django web server should typically not require over 512MB to run. Workers may require more than this, but we want to deploy those to EC2 instead, which has more favorable memory balances and GPU support. One possible source of memory bloat could be the side effects of importing third party modules. Rather than doing these imports at the file level, where the web server will also import them, they could be done only within the functions that actually need them, which will practically only be executed by the worker.
Generally, a Django web server should typically not require over 512MB to run. Workers may require more than this, but we want to deploy those to EC2 instead, which has more favorable memory balances and GPU support. One possible source of memory bloat could be the side effects of importing third party modules. Rather than doing these imports at the file level, where the web server will also import them, they could be done only within the functions that actually need them, which will practically only be executed by the worker.