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.
The two ways to run it
Section titled “The two ways to run it”| One instance | Several instances | |
|---|---|---|
| What you run | One hourd and a Postgres database | Two or more hourd, one Postgres database, and a Valkey they share |
| Good for | Development, small sites, a pilot | Production, high availability, more load |
| Stays up when an instance stops | No | Yes |
| Valkey | Not needed | Required |
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.
Scale up: one bigger instance
Section titled “Scale up: one bigger instance”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:
| Cores | Timecards a second | A million timecards |
|---|---|---|
| 1 | 1,400 | 12 minutes |
| 4 | 4,600 | under 4 minutes |
| 8 | 8,300 | about 2 minutes |
| 24 | 19,700 | under 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.
Scale out: more instances
Section titled “Scale out: more instances”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).
High availability
Section titled “High availability”To stay up through a stopped instance, an upgrade or a lost machine:
- 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.
- 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.
- 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.
- 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).
- 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 withhouradvantage_database_up. - 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.
Sizing for your load
Section titled “Sizing for your load”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.
- Count your peak. How many clocks, how many punches in the busiest ten minutes, and how many people’s timecards change in that time.
- Start with one instance per the guidance above, plus a spare. For most installs that is two instances.
- Run your real load against it. Use a test environment with your clocks, or replay a busy day.
- 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.
- Measure again after changes. New pay rules, more clocks or more tenants all change the load.
When to add more
Section titled “When to add more”Watch these, at your peak:
| What you see | What it means | What to do |
|---|---|---|
| Processors busy on every instance | The instances are the limit | Add cores, or add an instance |
Memory near the limit (houradvantage_memory_bytes) | An instance holds more than it was given | Add memory |
Work waiting for a database connection (houradvantage_db_pool_waiting) | The database is the limit | Give 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 made | Check the receiving system first, then add capacity |
| Timecards taking longer to update after a punch | Recalculation is behind | Add cores or instances |
The metrics page lists everything an instance reports.
Details
Section titled “Details”- 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).