Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

Design how a global scheduling platform stores and fires recurring events such as 09:00 every Monday in the user's zone, used by many teams.

We store each recurring event as a rule, a local time, a recurrence such as weekly on Monday and an IANA zone ID, never as a precomputed list of instants. The platform computes only the next occurrence from the rule with the current zone rules, keeps it in an indexed next_fire_at column, and a UTC-based dispatcher fires due events. Gaps and overlaps get a documented policy, and a tzdata change triggers recomputation of upcoming occurrences.

Why this question is asked

Recurring events look simple until the first daylight saving change, when half the users' 09:00 meetings arrive at 08:00 or 10:00. A shared scheduling platform multiplies the problem, because every team builds on its behaviour. Interviewers ask this design question to see whether we can separate what the user meant from how the machine fires it, and whether we think about the edge cases before they become incidents. In this answer, we will model the rule, compute occurrences step by step, design the storage and the dispatcher, define gap and overlap behaviour, and handle time zone data changes.

1Why Not Store a List of Instants?

The tempting design is to expand '09:00 every Monday in Europe/Paris' into the next 52 instants and store them. It is easy to query, but it is wrong twice. First, an instant computed today uses today's zone rules; if France changes its rules, every stored instant after the change shows the wrong local time. Second, a list must end somewhere, so someone has to remember to extend it, and edits to the rule must delete and regenerate rows.

What the user actually asked for is a wall-clock promise in a place. So the rule is the source of truth, and instants are computed from it, one at a time, as late as possible.

2The Data Model

A rule row holds the local time, the recurrence, the zone and the bounds. We can express the recurrence in the iCalendar RRULE format, which many teams already know, or in a simpler structure for the common cases. Next to it, a derived column holds the next occurrence as an instant, so the dispatcher can find due events with one indexed query.

SQL
CREATE TABLE schedule_rule (
id bigint PRIMARY KEY,
owner_team text NOT NULL,
local_time time NOT NULL, -- 09:00
recurrence text NOT NULL, -- FREQ=WEEKLY;BYDAY=MO
zone_id text NOT NULL, -- Europe/Paris, validated with ZoneId.of
starts_on date NOT NULL,
ends_on date,
gap_policy text NOT NULL DEFAULT 'SHIFT_FORWARD',
next_fire_at timestamptz, -- derived: next occurrence as an instant
tzdata_version text -- rules used to compute next_fire_at
);
CREATE INDEX ON schedule_rule (next_fire_at);

Notice that next_fire_at is a cache. If we lost it, we could recompute it from the other columns. Recording which tzdata version produced it tells us which rows to recompute when rules change.

3Computing the Next Occurrence

The computation works on the local timeline first and only then converts to an instant. We start from the current moment seen in the rule's zone, find the next date that matches the recurrence, attach the local time, and resolve it in the zone.

Java
Instant nextFire(Rule r, Instant now) {
ZoneId zone = ZoneId.of(r.zoneId());
LocalDate today = LocalDate.ofInstant(now, zone);
LocalDate date = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.MONDAY));
ZonedDateTime candidate = ZonedDateTime.of(date, r.localTime(), zone); // gap: shifted forward
if (!candidate.toInstant().isAfter(now)) { // already passed today
candidate = ZonedDateTime.of(date.plusWeeks(1), r.localTime(), zone);
}
return applyGapPolicy(r, date, candidate);
}
// Rule: 09:00 Monday Europe/Paris
// now = 2025-03-25T12:00Z -> next = 2025-03-31T07:00:00Z (09:00 at +02:00, summer time)
// now = 2025-03-20T12:00Z -> next = 2025-03-24T08:00:00Z (09:00 at +01:00, winter time)
Step throughComputing and firing one occurrence
  1. Read rule09:00, weekly Monday, Europe/Paris
  2. Now in the rule's zoneLocalDate.ofInstant(now, zone)
  3. Next matching dateTemporalAdjusters.nextOrSame(MONDAY)
  4. Local time valid in zone?
    YesResolve to instantNoApply gap or overlap policy
  5. Store next_fire_atwith tzdata version
  6. Dispatcher (UTC) fires when duethen computes the following one

6 steps in order. Play them, or step through them one at a time.

The two example results show the point of the design: the user sees 09:00 both weeks, while the instants differ by an hour because France moved to summer time on 30 March 2025. Notice also that the dispatcher itself never needs to know about zones. It only compares instants.

4Gaps and Overlaps: Decide and Document

Two nights a year in many zones, local time misbehaves. In a gap, such as 02:30 on the spring change in Europe/Paris, the local time does not exist. In an overlap, such as 02:30 on the autumn change, it happens twice. Java's default is to shift a gap time forward by the gap length and to pick the earlier offset in an overlap, but the platform must decide what it promises, because teams build on it.

A sensible default is to shift gap times forward, so a 02:30 job runs at 03:30, since skipping is usually worse than running late, and to fire only the first occurrence in an overlap. Teams that need 'skip' or 'fire both', such as a job that counts hours, choose it per rule with the gap_policy column. Whatever we choose, we write it in the platform's documentation and test it on real DST dates. To avoid firing twice by accident, each firing carries an idempotency key made of the rule ID and the local date, so a retry or a second overlap pass is recognised and dropped.

Default behaviour on the awkward nights
SituationExample (Europe/Paris)Platform defaultOption
Gap02:30 on 2025-03-30Shift forward: fire 03:30SKIP
Overlap02:30 on 2025-10-26Fire once, first offsetFIRE_BOTH
Normal day09:00 any MondayFire at 09:00 localnone

5Running the Dispatcher in UTC and Reacting to tzdata Changes

The dispatcher runs on servers in UTC and never calls now() without an explicit clock. It polls for rules whose next_fire_at is due, using SELECT ... FOR UPDATE SKIP LOCKED so several instances can share the work, publishes the event, and computes the next occurrence from the rule, not by adding seven days to the last instant. That last point matters: adding a fixed duration would drift by an hour at every DST change.

When a new JDK with new tzdata is deployed, the service compares the running tzdata version with the version stored on each rule. For rules in zones whose rules changed, it recomputes next_fire_at. Because we only ever store the next occurrence, the recomputation is cheap: one row per rule, not a year of instants.

6Follow-up questions

How do you handle 'last business day of the month' or 'every 31st'?

The rule format needs explicit semantics for these, the same way it does for gaps. For 'every 31st', iCalendar's RRULE skips months without a 31st, which surprises many users, so we offer 'last day of the month' as its own option and document both. Business days need a holiday calendar per region, which is a separate, versioned data set.

Why not just use a cron library per team?

Teams can, for their own jobs. A platform adds what each team would otherwise rebuild: persistent rules per user, a documented DST policy, idempotent delivery, recomputation on tzdata changes and monitoring. Internally, the platform may still use a cron expression parser to find the next date.

What happens if the dispatcher is down when an event is due?

When it comes back, it finds rows whose next_fire_at is in the past. The rule says what to do: fire late if the event is still useful within a tolerance, such as fifteen minutes, or skip and record a missed occurrence. Either way it then computes the next occurrence from the rule.

7Conclusion

In this answer, we designed a scheduler that stores recurring events as rules of local time, recurrence and IANA zone, never as lists of instants. It computes only the next occurrence from the rule with current zone rules, stores it in an indexed derived column with the tzdata version, and fires due events from a UTC dispatcher that never depends on the server's default zone. Gaps and overlaps follow a documented, per-rule policy with idempotent firing, and a tzdata change triggers recomputation of upcoming occurrences.

What to say in the interviewAbout 80 seconds aloud

Open with

The key decision is to store what the user meant, not instants. Each rule holds a local time like 09:00, a recurrence like weekly on Monday, and an IANA zone ID like Europe/Paris, with start and end dates.

Then, if they want more

From that, the platform computes only the next occurrence: it takes the current instant in the rule's zone, finds the next matching date, attaches the local time and resolves it to an instant with the current zone rules.

That instant goes into an indexed next_fire_at column along with the tzdata version used, so a dispatcher running in UTC just polls for due rows, with SKIP LOCKED for multiple instances, fires them and computes the next one from the rule, never by adding seven days.

For DST we document a policy: by default a time in the spring gap shifts forward and an overlap fires once, with per-rule options to skip or fire both, and firings carry an idempotency key of rule plus local date.

When a new tzdata version is deployed, we recompute next_fire_at for rules in zones that changed, which is cheap because we only store one occurrence per rule. Servers run in UTC, but nothing depends on the default zone.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Design how a global scheduling platform stores and fires recurring events such as 09:00...": https://scrivio-interview-library.netlify.app/java/date-and-time/64bb9f11ef/