0

I am totally new to this exciting world of programming and I am hoping it's just my inexperience that's to blame for not solving this myself:

Problem statement: My app created with flask framework, deployed on heroku has variables (stored in flask-session), which sometimes revert back to older states after being updated, at other times they don't get updated. My assumption is this has to do with distributed servers, which serve the variables at different states. I have tested this extensively locally on my computer and this issue never pops up, this only occurs when deployed.

How do I go about solving this issue please? I don't know what the exact problem maybe. I hope I have framed this question correctly to be helped. I will be in the comments to recieve any feedback to improve my question and to get an answer. thanks.

Further information: I developed a quiz app which; for each question, on the back end it queries a database then pushes this info to the front end where the user selects an answer, javascript lowers the number of lives or increases the score (depending on right or wrong answer) this lives and score info is passed to the back end and stored in "sessions". My 1st problem is; the lives and scores values don't update sometimes at other times it updates then it reverts back to previous states. My second problem; is the questions also repeat sometimes when the lives and scores variables states don't change.

Thanks in advance for your help.

  • Does this answer your question? [Are global variables thread safe in flask? How do I share data between requests?](https://stackoverflow.com/questions/32815451/are-global-variables-thread-safe-in-flask-how-do-i-share-data-between-requests) – ChrisGPT was on strike Jun 28 '20 at 11:30
  • Welcome to Stack Overflow! Please take the [tour] and read [ask]. Ideally, most questions here should come with some code as a [mcve]. Describing your code isn't as clear as showing it to us. I think I linked to a helpful duplicate, but there's no way to know without more information. – ChrisGPT was on strike Jun 28 '20 at 11:31

1 Answers1

0

Issue Files are uploaded to the app but then disappear or are deleted after a while.

Resolution The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Each dyno boots with a clean copy of the filesystem from the most recent deploy. This is similar to how many container based systems, such as Docker, operate.

In addition, under normal operations dynos will restart every day in a process known as "Cycling".

These two facts mean that the filesystem on Heroku is not suitable for persistent storage of data. In cases where you need to store data we recommend using a database addon such as Postgres (for data) or a dedicated file storage service such as AWS S3 (for static files). If you don't want to set up an account with AWS to create an S3 bucket we also have addons here that handle storage and processing of static assets

https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted

Muhammad Zakaria
  • 1,269
  • 6
  • 14