Forums

Databases and logins with Flask

I'm pretty new to Python and Flask and this whole programming thing in general, but couldn't you use dictionaries to store user logins and stuff? Why do you need databases?

Good question! The short answer is: because dictionaries are only stored in RAM, whereas databases are stored on disk.

You see, the worker process that handles your web app isn't guaranteed to live forever -- it's meant to be able to be killed and restarted at any moment. Paying users also actually have multiple web workers, and they all need to be able to handle user's requests consistently.

So the database is used to provide permanent storage, and also a "single source of the truth", which multiple workers can agree on. databases also have lots of clever technology (transactions, locks) to ensure that multiple parallel processes can read and write from it simultaneously, while maintaining coherent data...