Help, my web page is running slowly!

I was once presented the following question as a part of a job interview: ‘You have a web page that is running slowly. How do you find out why it’s running slowly.’ I really enjoyed answering this question and have used it myself when conducting interviews. Why do I like it? Firstly it shows how someone approaches a problem and how they can systematically work through it. Secondly there is no single correct answer, but many possible solutions. It allows people to demonstrate their experience of similar issues they have worked through before. It will also, hopefully demonstrate their appreciation of all the different places a web page can hit a bottleneck.

So how do you find out why it’s running slowly? First you need to get a better grip on the problem, and find out under what scenarios its running slowly:

  • Is it happening on all pages? Is the page slow to load or is it a particular action on the page?
  • Is it consistently slow, or does the page response time vary?
  • Is it slow for all users or types of users?
  • Is it slow all environments? I.e. is it slow in live, testing, staging environments? Is it slow on a developer local development environment? Is it happening in one live environment but not another?
  • Are there particular times of the day or week when the site is slow?
  • Is it slow for specific clients? Is it their browsers? Is it their network connection?
  • Is it happening when the server resources hit a certain percentage? Or a certain number of users or database connections?
  • Does it happen when other processes are happening, like a long running report or a database backup or an app pool recycle.
  • In a load balanced environment, is it affecting specific servers or all servers?
So what could be causing the slow pages?
  • Slow running database queries, or badly written data access. I have found this is one of the most likely candidates.
  • Poor performing code, on server or client.
  • The general page life cycle. What common action take place on every page load? Can these things be streamlined or cached? You want to make sure a basic page loads as quickly as possible, otherwise you have a bad foundation to build from.
  • Database contention.
  • To many database connections.
  • Bad server or load balancer configuration.
  • Large web page, CSS, JavaScript or image files. Can minification and bundling of files help? How about using a content delivery network help? Can preloading resources help?
  • Could using a single page application help?
  • Poor (or no) caching strategy.
  • High memory usage or CPU utilisation.
  • Do you need to scale up (more powerful servers) or out (increase the number of servers).
  • Internet connection between client and server.
  • Network connection between servers (e.g. check that the connections between servers within a data centre don't route externally)
  • Do any application processes have blocking methods? For example when a user clicks a button does it have to wait on a long running process or a third party API result. If so it may be better to queue these, and process them asynchronously.
If you are ever asked this question in an interview, there is a chance the interviewer is having problems with a slow running site and is trying to get some ideas on how to fix it. You may end up solving your first bug for the company without even working there.

So what happened in my interview? I got the job, and one of my first assignments in the new role? To fix the slow running page.

Alex Orpwood Written by:

Software developing and architecting for 20 years. Satellite monitoring by day, writing my own app by night. More about me