Building On-call: Time, timezones, and scheduling
incident.io's on-call scheduler computes who is on shift from rotations with working hours, round-robin handovers and overrides, and getting it right depends on being precise about local time, offsets, IANA timezones, instants and durations. The design keeps everything as UTC instants (Postgres timestamptz, Go's time package) and converts to wall-clock time only at the edges or in isolated, well-tested calculations such as working hours. Users wanted schedules shown in their own timezone, and sometimes several at once, rather than the schedule's timezone. Correctness rests on unit-tested building blocks, JSON snapshot tests of schedule evaluations flagged in PRs via danger.js, and a periodic runtime audit job that re-evaluates active schedules against the cached on-call state.
Related posts
- Who's on call? How we improved schedule rendering performance 2,500x
incident.io mediumAdeptincident.io's on-call schedule renderer, which computes future shifts on the fly from rotation config, working hours and fair-scheduling rules, became dramatically faster through a series of fixes culminating in a ~2,500x speedup. Earlier wins came from request validation and context cancellation after a runaway 2092 date, replacing repeated linear entry splitting with sorted binary-search insertion (850ms to 100ms, though a Go pointer-copy aliasing bug forced rollbacks), and removing hot-path waste like string weekday comparisons, unused UUID generation, repeated time.LoadLocation and clock-time parsing for about 40% more. The largest gain came from Claude Opus 4.6 building a V2 renderer that avoids iterating every handover, validated by requiring identical output to V1 across the existing test suite and rolled out behind a feature flag with an audit job.
- Run Scheduled and Recurring Tasks with Cron
Railway mediumAdeptCron runs commands on time-based schedules but keeps no job history, has no retries and does no concurrency control, so reliability depends on the job itself. The guide covers the five-field schedule syntax, including the day-of-month/weekday OR pitfall and timezone/DST issues, and recommends idempotent upserts, structured start/success/error logs, explicit connection cleanup, and Postgres advisory locks to prevent overlapping runs. On Railway, cron triggers a service's start command in UTC with a 5-minute minimum interval and a single active execution. A process left alive by open handles or pending promises causes later runs to be skipped.
- Tracking Time Without Clock
TigerBeetle mediumAdeptInstead of threading a full virtualized Clock interface through every component, two lighter patterns often suffice for handling time in reliable systems. Passing a `now: Instant` argument to methods (call-site dependency injection) lets components like TigerBeetle's adaptive replication routing measure durations without owning a clock, and makes edge cases like time overflow trivial to test. For scheduling future work, a `tick` method invoked at a fixed cadence by the caller gives coarse but sufficient time resolution and greatly simplifies control flow and testing.
- Three Clocks are Better than One
TigerBeetle mediumAdeptTigerBeetle builds a fault-tolerant "cluster time" by measuring clock offsets to peers during keepalive probes. Each offset combines the peer's wall-clock timestamp with half the round-trip time, and the best low-latency samples from windows of up to 20 seconds are fed to Marzullo's algorithm, which yields bounds agreed by a majority of clocks. That lets a server correct its system time when NTP silently fails, or shut down safely if too many clocks are faulty. Elapsed time should be measured with CLOCK_BOOTTIME rather than CLOCK_MONOTONIC, which stops counting during system suspend (e.g. VM migration), or CLOCK_MONOTONIC_RAW, which exists for NTP to measure oscillator drift.
- Fixing JavaScript Timezone Issues
Neon mediumAdept
A parking booking app stored Italian users' midnight bookings as 6:00 PM the previous day in a US-hosted Postgres database, because `new Date(selectedDate)` attached the browser's local timezone before the value reached the API. The fix was to build a plain `YYYY-MM-DD HH:MM:SS` string with no timezone information and store it directly, so the database keeps exactly the wall-clock time the user picked. The post ends with a short endorsement of Neon's free plan and easy connectivity.