
Why my app took 20 seconds to open, and what a region has to do with it..
A student's debugging story: nine database round trips, servers on the wrong side of the world, and the first AWS idea that made sense to me.
I built a workout tracker for myself. It logs sets, supersets and body weight, and it is installed on my phone like an app. For weeks it had one problem. Opening it took 20 to 30 seconds.
I'm a third-year CS student and I'm just starting to learn AWS. This is the bug that made one AWS idea click for me, so I'm writing it down.
Where I looked first
My first guess was the framework or the database. I almost wanted it to be one of them, because then the fix would be "switch tools". But a 20 second load pointed at something specific in my own code, so I read the dashboard page before changing anything.
What was actually wrong
The dashboard made nine database requests, one after the other, before it showed anything. Each one waited for the one before it.
Two of those queries were also heavy. One loaded all of my roughly 870 exercises on every visit, for a dialog that shows 50 at a time and that I might never open. The other pulled every set I had ever logged and sorted them in JavaScript just to find one maximum. It would have gotten slower the longer I trained.
I ran the independent requests together instead of in a row, which took nine round trips down to three. The exercise list now loads only when the dialog opens. The heaviest set is now fetched on its own, one row at a time.
The part about regions
Even after that, the app was slower than it should be. The reason is physical. My database runs in Seoul, in the AWS region ap-northeast-2. My hosting platform had put the app's server functions in Washington D.C.
So every database request crossed the Pacific Ocean and back. Nine requests in a row on that path is slow. Each page also made two more trips just to check who was signed in.
I moved the functions to Seoul, next to the database. I also changed the sign-in check so the server verifies the session itself against a cached key, instead of asking the auth service every time. That removed two round trips per page.
What I took from it
A region is not just a setting in a drop-down menu. It is where your code and your data physically live, and distance adds delay to every request. If your app makes several requests in a row, you pay that delay several times.
Opening the app now takes about two seconds, down from 20 to 30.
What I'd do differently
- Check where the server and the database are before anything else.
- Count the requests a page makes before blaming the tools.
- Don't switch a whole stack to fix something you haven't measured.
I also have a trade-off to be honest about. Checking the session on the server means a session revoked on the auth side keeps working in the app's page checks until its token expires, up to an hour. Data access is still protected by database rules. For a one-person app I accepted that. For something bigger, I would think harder.
What's next
I'm starting with AWS fundamentals now, and regions and latency are the first thing I could connect to something I broke myself. I'd like to hear from anyone who has hit the same problem. How do you decide which region to put a new project in?
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article