Skip to content

Sizing and scaling

Hour Advantage scales two ways. Scale up: give an instance more cores and memory, and it does more work. Scale out: run more instances side by side, and they share the work. Use both. There is no fixed limit on employees or clocks.

This page covers how to size an instance, when to add another, and how to run several so that one can stop without anyone noticing.

One instanceSeveral instances
What you runOne hourd and a Postgres databaseTwo or more hourd, one Postgres database, and a Valkey they share
Good forDevelopment, small sites, a pilotProduction, high availability, more load
Stays up when an instance stopsNoYes
ValkeyNot neededRequired

There are no other combinations. One instance keeps everything in its own process. Several instances share a Valkey, which carries what they tell each other and the cache they share (a shared Valkey). An instance refuses to start if it would break this: a second instance without a Valkey, for example, says so and stops.

An instance uses every core it is given. Time and Attendance works out timecards on all of them at once, and the clock-facing work and the deliveries to your systems share them too.

How many two-week timecards one instance works out a second, by cores, with a typical pay policy (rounding, daily and weekly overtime, a night premium and lateness), measured on a 24-core desktop:

CoresTimecards a secondA million timecards
11,40012 minutes
44,600under 4 minutes
88,300about 2 minutes
2419,700under a minute

Your pay rules and hardware change these numbers. Measure your own.

An instance sizes itself from the processors it can use: a container’s CPU limit on Linux, or HOURADVANTAGE_CPUS if you set it. Give it memory to match: at least 1 GiB, and more as it serves more clocks (capacity planning).

Scale up first. One bigger instance is simpler to run than several small ones, and the work of one person or one clock is never split across instances anyway.

Add instances when one is not enough, or when you need it to stay up.

  • Every instance is the same. Same version, same settings, same database, same Valkey. Any instance serves any clock and any request.
  • Any load balancer works. No sticky sessions are needed. A clock’s requests may reach a different instance each time.
  • Work is shared out by itself. Each person’s timecards, each sink’s deliveries, each sync group and each job is handled by one instance at a time. When an instance stops, the others take over its share.
  • Instances can differ in size. Each uses the cores it has.

The database is shared by every instance. As you add instances, watch it too (when to add more).

To stay up through a stopped instance, an upgrade or a lost machine:

  1. Run at least two instances, each able to carry the full load alone. This is N+1: one spare. With three, you can lose one and still have a spare while you replace it.
  2. Spread them out. Put instances on different machines, and in different zones or racks where you have them, so one failure takes only one instance.
  3. Make the Valkey highly available. Use Valkey behind Sentinel (at least three Sentinels), a Valkey cluster, or a managed Valkey with failover. A lost Valkey stops instances from telling each other what changed until it is back.
  4. Make Postgres highly available. Use a standby with automatic failover, or a managed Postgres that has it. Postgres is the record: every punch and every timecard is kept there (database failover).
  5. Let the load balancer check readiness. Point its health check at /api/ready. An instance that is starting or stopping says it is not ready, and the balancer stops sending it requests (readiness). Watch whether each instance reaches the database with houradvantage_database_up.
  6. Upgrade one instance at a time. A rolling upgrade keeps the others serving (upgrades).

Clocks keep the punches they cannot send, and send them once they reach an instance again. So an outage delays punches rather than losing them, for as long as the clocks have room to keep them.

Size for your busiest moment, not your average. For time and attendance, that is shift change: everyone punching within a few minutes, and the timecards being worked out right after.

  1. Count your peak. How many clocks, how many punches in the busiest ten minutes, and how many people’s timecards change in that time.
  2. Start with one instance per the guidance above, plus a spare. For most installs that is two instances.
  3. Run your real load against it. Use a test environment with your clocks, or replay a busy day.
  4. Leave room. At the peak, keep each instance’s processors and the database’s well below full, so a lost instance or a busier day still fits.
  5. Measure again after changes. New pay rules, more clocks or more tenants all change the load.

Watch these, at your peak:

What you seeWhat it meansWhat to do
Processors busy on every instanceThe instances are the limitAdd cores, or add an instance
Memory near the limit (houradvantage_memory_bytes)An instance holds more than it was givenAdd memory
Work waiting for a database connection (houradvantage_db_pool_waiting)The database is the limitGive the database more processors or faster storage before adding instances
A sink falling behind (houradvantage_sink_oldest_waiting_seconds)Deliveries are slower than events are madeCheck the receiving system first, then add capacity
Timecards taking longer to update after a punchRecalculation is behindAdd cores or instances

The metrics page lists everything an instance reports.

  • What is shared: Postgres holds every record. Valkey holds only what can be rebuilt from Postgres: the cache and what instances tell each other. Losing Valkey loses no data.
  • Moving between the two ways: to go from one instance to several, add a Valkey, give every instance its address (HOURADVANTAGE_CACHE_URL), and start the others. To go back, stop all but one and remove the address.
  • Several installs on one Valkey: give each its own install id (HOURADVANTAGE_CACHE_INSTALL).