Member-only story

Software Engineer Interview: Is there a way to count how many people are visiting my website?

Marika Lam
3 min readAug 15, 2024

--

Recently I was asked by an interviewer to architect a user search that will result in a page with the parsed results and for each result, the number of people viewing that page needs to be shown.

So the question is how do we determine how many people have visited the website? That includes how many people went to the link (increases a counter) and how many people have left (decreases the counter).

Here a few solutions that can work.

Option 1: Use Persistent Data Storage

First off, you can’t do it using JavaScript or HTML because you do not have persistent storage. That means that once the client UI side is closed, all information is closed. Therefore, you will need a database to keep track of how many people have visited your page (for example, MySQL and PHP).

A server side language will have to be used to store data in the database. Then you can retrieve the data using AJAX requests to make it dynamic. JavaScript is a client side language, so it cannot be used for this counter.

  1. On load, send a request to PHP script to increment counter.
  2. Then in the PHP script, return the number of views and manipulate the DOM…

--

--

No responses yet