I was wondering how a real time browser game work like ogame?
How do you constantly update stuff like resources?
My only suggestion is having a computer turned on 24-7 but that can't be it.
Usually, while people are not interacting with a game, they have pretty steady flow of resources. So between events that change this flow you don't need to update amounts, but calculate it instead.
For example. Suppose in some game there is a stone
resource. Player starts with 0 stones
and is able to build stone quarry
that will produce 1 stone
per hour, which then can be upgraded to say level 2 so it can produce 2 stones
per hour. Initially, we know that player does not have stone quarry
so his stone
income is 0 per hour. Then player builds stone quarry
and we make following log entry:
at time T0 player P build stone quarry. He had 0 stones at that moment and stone income is now 1 stone per hour.
Starting from this moment, if nothing happens we can simply calculate the amount of stones at any moment, we don't need to keep it updated.
If player spends stones on something we add following log entry:
at time T1 player P spent X stones on <something>. He now has S1 stones and stone income is 1 stone per hour.
again after that we have full information for calculating number of stones at any moment even if our servers crash (assuming logs are hardened in some way)
then player upgrades stone quarry
:
at time T2 player P upgraded stone quarry to level 2. He had S2 stones at that moment and stone income is now 2 stones per hour.
So the idea is to log timestamp, resource amount and resource income rate whenever amount or income changes. Then you would have all the data to calculate amount of resource at any point of time in future.