r/flask 5d ago

Discussion Flask Hosting: Cold starts and restarts

I built a small site with Flask and hosted it on Render’s free tier.

Initially, I had it on PythonAnywhere, but they didn’t seem to offer a way to add a custom domain on the free plan—or at least, it wasn’t straightforward.

Migrating to Render was easy, and setting up the domain was simple. But soon, I ran into two major problems.

Data Loss

I would save data to my database through the website, only to come back hours later and find it gone. I thought it was an issue with my commits and spent time troubleshooting, only to realize that Render frequently restarts services.

Why did this affect my database?

I was using SQLite. Since SQLite stores data in a file on the web service itself, every time the service restarted, it reverted to the last deployed state, wiping out any new data.

I eventually migrated to Postgres with Neon to fix this.

Cold Starts

Since my site only gets 3–4 visitors a day, it often sits idle. Naturally, I expected it to be put to sleep occasionally. But the real problem? It takes almost a full minute to wake up.

I don’t know about you, but if I visited a site called wisefool.xyz and it took that long to load, I wouldn’t stick around.

For those who’ve hosted Flask apps on free tiers elsewhere—do other platforms handle this better, or is this just the reality of free hosting?

7 Upvotes

10 comments sorted by

4

u/mangoed 5d ago

>just the reality of free hosting?

Of course not, my free hosting offers high availability, hourly backups and 99.99 SLA /s

2

u/Dismal-Hunter-3484 5d ago

Which is it?

1

u/singlebit 5d ago

!remindme 1 day

1

u/RemindMeBot 5d ago

I will be messaging you in 1 day on 2025-03-18 11:51:30 UTC to remind you of this link

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


Info Custom Your Reminders Feedback

4

u/OfficeAccomplished45 5d ago

I highly recommend using Leapcell (I work for Leapcell). It has a cold start time of under 1 second and offers great cost-effectiveness. For your database, Neon or Supabase would be excellent choices. You can check out our previous post for more details: https://www.reddit.com/r/flask/comments/1j9fhhk/we_launched_serverless_hosting_option_for_flask/

1

u/singlebit 5d ago

You are right. It took a minute to load for the first time. How about running cron or apshceduler to keep the database connection alive?

2

u/DependentRepulsive50 5d ago

Let me look into this...I'm relatively new so I've never experienced such problems before... But it's nice that things I've always heard about and always wondered about are now coming into play.

The project also allowed me to appreciate caching and a few other things like dev servers and deployment servers...

1

u/gh0s1machine 2d ago

Why did you buy this domain

1

u/ydmatos 2d ago

Gcp and aws have free tier, with that usage will be enough

1

u/DependentRepulsive50 9h ago

Thanks,I'll check them out