Quick revision
The short answer
Past events and fixed instants are stored as timestamptz in PostgreSQL, which keeps them in UTC, and handled as Instant or OffsetDateTime in Java. A future appointment that people define in local time is stored as the local date-time plus the IANA zone id, such as Europe/Berlin, and turned into an instant only when we need one, with DST gaps and overlaps handled on purpose. We also pin the JDBC and JVM time zone handling to UTC and keep the tz database current everywhere.
What to remember
In this answer, we saw that past events and instants belong in timestamptz and Instant or OffsetDateTime, while future appointments defined in local time are stored as a local date-time plus an IANA zone id and converted with ZonedDateTime.of when needed, with DST gaps and overlaps handled deliberately. Setting hibernate.jdbc.time_zone and the JVM zone to UTC removes surprises from defaults, and keeping the tz database updated in both the JDK and PostgreSQL keeps the rules correct.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Past events and fixed instants are stored as timestamptz in PostgreSQL, which keeps them in UTC, and handled as Instant or OffsetDateTime in Java. A future appointment that people define in local time is stored as the local date-time plus the IANA zone id, such as Europe/Berlin, and turned into an instant only when we need one, with DST gaps and overlaps handled on purpose. We also pin the JDBC and JVM time zone handling to UTC and keep the tz database current everywhere.
Why this question is asked
Time bugs are some of the most expensive bugs to find, because the system works for months and then fails on two nights a year. A patient who arrives an hour late because our reminder was wrong is a very visible failure. Interviewers ask this to see whether we know the difference between a moment in time and a time on a wall clock, and how each should be stored. In this answer, we will recap the vocabulary, see why the appointments shifted, model past instants and future local times, handle DST gaps and overlaps in Java, and set the database and JVM up so the defaults cannot surprise us.
1A Quick Recap of the Vocabulary
An instant is a single point on the global timeline, the same everywhere: the moment a payment was captured. In Java this is Instant. A local date-time is what a wall clock shows, 09:30 on 30 March, without saying where; in Java this is LocalDateTime. A time zone such as Europe/Berlin, identified by an IANA zone id from the tz database, is a set of rules that says which offset from UTC applies on each date. An offset such as +02:00 is just the difference from UTC at one moment.
Daylight saving time, DST, means a zone's offset changes twice a year. Berlin uses +01:00 in winter and +02:00 in summer. On the change days, some local times do not exist (a gap) and some happen twice (an overlap).
2Why the Appointments Shifted
timestamp without time zone in PostgreSQL stores a plain wall-clock value with no zone. It means nothing until someone decides which zone it was in. If the application writes UTC values into it on one server and reads them on another whose JVM default zone is Europe/Berlin, the driver interprets them in Berlin time, and every value moves by the offset, which itself changes at DST. A second common cause is converting a future local time to UTC using today's offset, for example with a fixed +01:00 in winter for a July appointment, so after the clocks change the stored instant is an hour off.
Both bugs have the same root: storing the wrong kind of value, then letting a default zone fill the gap.
| Value | PostgreSQL column | Java type |
|---|---|---|
| Payment captured, login time, audit event | timestamptz | Instant or OffsetDateTime |
| Future appointment at 09:30 in Berlin | timestamp + text zone id | LocalDateTime + ZoneId |
| Clinic opening hours, 08:00 to 17:00 | time + zone id of the clinic | LocalTime + ZoneId |
| Date of birth | date | LocalDate |
| Avoid | timestamp without zone for instants | java.util.Date, fixed offsets |
3Storing Past Instants
For anything that has already happened, the moment is what matters. timestamptz, timestamp with time zone, converts any input to UTC and stores it; on output it converts to the session's TimeZone setting. Despite its name, it does not store the zone, it stores an instant. In Java we map it to Instant or OffsetDateTime, which the PostgreSQL JDBC driver supports directly.
4Storing Future Appointments
A future appointment is different. The clinic and the patient agreed on 09:30 local time in Berlin. If Germany changed its DST rules before that date, everyone would still expect 09:30 on the wall clock, not whatever instant we calculated months ago. So the truth is the local date-time plus the zone id, and the instant is derived from them.
Here timestamp without time zone is correct, because the value really is a wall-clock time and the zone is stored right next to it. For queries such as 'all appointments in the next hour', we can keep a derived starts_at timestamptz column that a job recomputes whenever the tz database is updated.
5Handling DST Gaps and Overlaps
On 29 March 2026 Berlin clocks jump from 02:00 to 03:00, so 02:30 does not exist. On 25 October 2026 they go from 03:00 back to 02:00, so 02:30 happens twice. ZonedDateTime.of has defined behaviour for both, and we should choose deliberately rather than accept it by accident.
- Load starts_local and zone_id2026-07-14 09:30, Europe/Berlin
- Is the local time in a DST gap?YesApply the booking rule: reject or shiftNoContinue
- Is it in a DST overlap?YesUse the documented offsetNoUse the only offset
- Compute the Instant2026-07-14T07:30Z
- Schedule the reminderfor example 24 hours before
5 steps in order. Play them, or step through them one at a time.
For booking, the simplest rule is to reject slots in a gap when they are created, which clinics rarely use anyway at 02:30, and to pick and document one offset for overlaps. The important thing is that the behaviour is a decision we tested, not a surprise.
6Making the Defaults Harmless
Even with the right types, defaults can still change values in transit. We set the JVM to UTC with -Duser.timezone=UTC so nothing depends on the host, and tell Hibernate to use UTC for JDBC timestamps with spring.jpa.properties.hibernate.jdbc.time_zone=UTC. Server and database sessions use UTC too. Then we keep the tz database current: new rules arrive several times a year, the JDK gets them through updates or its tzupdater tool, and PostgreSQL either bundles them or uses the operating system's copy, so both need patching. When rules change, we recompute any derived instants for future appointments.
7Follow-up questions
Why not store everything as UTC instants?
Because for future local events the instant is not the truth. If a government changes its DST rules after booking, a stored instant becomes an hour wrong, while a stored local time plus zone id stays right and we simply recompute the instant.
Why store the zone id and not the offset?
An offset such as +01:00 is valid only for one moment. It cannot tell us that the same clinic is at +02:00 in July. The zone id carries all the rules, past and future.
What should the API send?
For instants, ISO 8601 strings with an offset or Z, such as 2026-07-14T07:30:00Z. For appointments, the local date-time and the zone id as separate fields, so clients show the clinic's wall-clock time correctly.
8Conclusion
In this answer, we saw that past events and instants belong in timestamptz and Instant or OffsetDateTime, while future appointments defined in local time are stored as a local date-time plus an IANA zone id and converted with ZonedDateTime.of when needed, with DST gaps and overlaps handled deliberately. Setting hibernate.jdbc.time_zone and the JVM zone to UTC removes surprises from defaults, and keeping the tz database updated in both the JDK and PostgreSQL keeps the rules correct.
Open with
The shift happens because a timestamp without time zone is a wall-clock value with no zone, so whichever default zone reads or writes it changes its meaning, and with DST that offset changes during the year.
Then, if they want more
I would separate two kinds of values. Past events and fixed instants, like a check-in or a payment, go into timestamptz, which PostgreSQL stores as UTC, and map to Instant or OffsetDateTime in Java.
Future appointments are agreed in local time, so I would store the local date-time plus the IANA zone id, such as Europe/Berlin, because zone rules can change before the appointment and the wall-clock time is what people expect.
When I need an instant, for a reminder for example, I compute it with ZonedDateTime.of the local date-time and ZoneId, and I handle DST explicitly: a time in the spring gap like 02:30 is moved forward by default, and in the autumn overlap Java picks the earlier offset unless I ask for the later one.
I would reject gap times at booking and document the overlap rule. Then I would pin the JVM to UTC and set hibernate.jdbc.time_zone to UTC so nothing depends on server defaults, and keep the tz database updated in both the JDK and PostgreSQL.
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.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
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 "Your system stores appointments for clinics in many countries. Some columns are...": https://scrivio-interview-library.netlify.app/databases/data-modeling/30d80d74f8/