Hadi Khezrpor
Hadi Khezrpor

Reputation: 401

how to save users visits in an optimized way in Laravel 5.4

I am saving my users visits statistics like this in mySQL database :


my question is will my mySQL database handle this amount of visits like 100,0000 per day? and can it make problems in 5 years being saved like this?(100000 per day)

and if the answers are YES, so what is the optimized way to do this(I don't want to empty my visits table)

Upvotes: 0

Views: 641

Answers (1)

MEDZ
MEDZ

Reputation: 2295

First of all, you may need to rethink MySQL. If you want to keep staying in RDBs you may want to research postgres, and with some optimization, it can handle the number of rows. On the other hand if you open to switch to NoSQL, then i recommend elastic search. It can handle this kind of data very well.

If you chose to stay with postgres/mysql. Then you can restructure your schema by separating the visitor data (unique users) from the visited_pages data as follows:

visitors


 - id
 - ip_address
 - device
 - first_visit (created_at)
 - latest_visit (updated_at)

visited_pages

 - id
 - page_title
 - page_route
 - first_visit (created_at)
 - latest_visit (updated_at)

page_visit

 - id
 - visitor_id
 - page_id
 - visited_at (created_at) //no need for updated at

The largest table will be the last one and it won't contain much data. and you will not have to use the same data like route, page title, ip address every time.

Upvotes: 2

Related Questions