Prompt and Where It Applies
A Linux service reads CLOCK_REALTIME when a request starts and enforces a two-second timeout with “current time minus start time.” The same source timestamps audit records, schedules a daily job at 09:00 local time, and orders events from several services. After an NTP correction or a manual clock change, wall time may jump forward or backward. Some requests expire immediately; others wait far longer than two seconds.
Choose a clock or ordering mechanism for local elapsed time and timeouts, a lease that must expire while the machine is suspended, a human calendar schedule, durable audit time, and cross-machine causal ordering. Cover process restart, serialization, clock skew, and a verification plan.
The two-second timeout, suspend behavior, and schedule are interview assumptions. The main Linux clocks are CLOCKREALTIME, CLOCKMONOTONIC, and CLOCK_BOOTTIME; a language runtime may wrap them. The category is general because the core skill is operating-system time semantics and reliability reasoning rather than one application framework.
A system-design interview resource updated in 2026 treats wall clocks, monotonic clocks, clock corrections, and skew failures as one practice topic. The POSIX.1-2024 rationale, Linux man-pages, and Go documentation provide independently checkable API boundaries. These sources establish current relevance and durable preparation value; they do not establish a company-specific prompt or interview frequency.
What the Interviewer Is Evaluating
First, can the candidate ask what question a time value must answer? Wall time answers “what civil or UTC instant is it?” and fits audits, certificate validity, and calendar schedules. Monotonic time answers “how much time elapsed in this runtime?” and fits durations, backoff, and timeouts. An API name or nanosecond precision does not substitute for semantics.
Second, does the candidate know that monotonic does not mean perfectly uniform, globally consistent, or always advancing? Linux CLOCK_MONOTONIC does not suffer discontinuous jumps from setting system time and does not move backward, but gradual NTP adjustments affect its rate and it excludes system suspend. Consecutive reads may even return the same value.
Third, can the candidate distinguish CLOCKMONOTONIC, CLOCKBOOTTIME, CLOCKMONOTONICRAW, and CPU time? BOOTTIME is monotonic and includes suspend. MONOTONIC_RAW avoids gradual NTP adjustment and is useful for low-level clock measurement, but it is not the default application-timeout answer. Process and thread CPU clocks count execution on a CPU, not time spent waiting.
Fourth, will the candidate avoid persisting or transmitting a local monotonic reading as though it were a universal timestamp? Its origin has no calendar meaning, and it is not a durable timeline across restarts. Physical timestamps alone cannot prove cross-machine order. A business sequence, database commit position, consensus log, Lamport clock, or hybrid logical clock must carry correctness when the requirement calls for it.
Finally, can the candidate inject real clock failures? Waiting two seconds once covers none of wall-clock steps, slewing, suspend, restart, or remote skew.
Questions to Clarify Before Answering
- Does two seconds mean active runtime or real elapsed time? A request timeout while the process runs normally uses
CLOCKMONOTONIC. A local lease that must be gone after a one-minute suspend should considerCLOCKBOOTTIME. - Must the deadline survive a process restart? An in-memory monotonic deadline belongs to one running instance. Persist an authoritative wall-time expiry or business state, then establish a bounded local budget after startup.
- Which time zone defines “daily at 09:00,” and what happens in a DST gap or fold? A calendar job needs an IANA zone and a policy for missing or repeated local instants. Monotonic time cannot express that rule.
- What must an audit record prove? A readable UTC instant supports search and compliance, but ties, clock rollback, and multi-host skew also require a stable ID, commit sequence, or causal field.
- Does cross-service ordering serve display, deduplication, causality, or a strict total order? Display may tolerate skew. A ledger or replicated state machine usually needs a commit authority or consensus log rather than “larger timestamp wins.”
- How does the target platform handle suspend and VM migration? Linux defines its clock semantics, but the actual language runtime, host, virtualization layer, and resolution still need version-specific verification.
- Does synchronization step or slew the clock? A wall-clock step directly breaks duration subtraction. Slewing leaves monotonic time nondecreasing but changes its rate slightly relative to the raw hardware counter.
30-Second Answer Framework
“I choose a clock based on the question. Audit timestamps and daily 09:00 schedules need durable wall time. A two-second duration or timeout inside one process uses a monotonic clock so a wall-clock step cannot expire it early or late. If suspend must consume a lease, Linux provides CLOCK_BOOTTIME. I neither serialize monotonic readings nor compare them across restarts or machines. Cross-service wall time is observational; a business version, commit log, or logical clock supplies correctness. I would inject forward and backward wall-clock steps, then test slewing, suspend, restart, and host skew against a separate invariant for each use case.”
Step-by-Step Deep Dive
Step 1: Split One Time Value into Five Requirements
Build a decision table instead of assigning one source to the entire system:
| Requirement | Recommended basis | Main reason |
|---|---|---|
| Local duration, retry backoff, two-second timeout | CLOCKMONOTONIC | Immune to discontinuous wall-clock changes |
| Local lease that consumes suspend time | CLOCKBOOTTIME | Monotonic and includes suspend |
| UTC audit instant, certificate validity | CLOCK_REALTIME | Unix Epoch meaning; durable and exchangeable |
| Daily 09:00 local time | Wall clock + IANA zone + DST policy | Defined by a human calendar |
| Correct cross-host order | Business version, commit log, or logical clock | Physical skew means a timestamp does not prove causality |
| CPU cost in a profiler | Process or thread CPU clock | Counts time actually executing on a CPU |
One record may carry two time dimensions. For example, a request log stores a UTC observedat for retrieval while the process computes durationms from a monotonic start reading. The fields answer different questions and do not replace each other.
Step 2: Explain Why Wall Time Breaks Duration Subtraction
Suppose the code evaluates elapsed = realtimenow - realtimestart. If wall time steps forward by 90 seconds after the request begins, the next check falsely declares a timeout. If it steps backward by 90 seconds, elapsed can become negative and the request may wait until wall time catches up. NTP may also correct time gradually by changing the clock rate. Wall time must align with external civil time, so an application cannot assume strictly increasing consecutive readings.
Take both start and current readings from the same monotonic clock, or use a timer/deadline API explicitly based on it. Never subtract one realtime reading from one monotonic reading; their origins differ. Do not pick MONOTONIC_RAW merely because “raw” sounds more accurate. Application timeouts normally benefit from a nondecreasing clock whose seconds stay disciplined toward real seconds, which is what the ordinary POSIX/Linux monotonic clock provides.
Step 3: Decide Whether Suspend Spends the Budget
Linux CLOCK_MONOTONIC stops accumulating while the system is suspended. If a laptop sleeps for one minute, a local 30-second MONOTONIC timer may still have time left after resume. That can fit work defined in runnable time, but not a session or security lease that must expire while the machine sleeps.
CLOCK_BOOTTIME includes suspend and fits the latter rule. Waking a suspended machine to perform work additionally requires the appropriate alarm capability and permissions; choosing BOOTTIME does not wake it by itself. A lease that spans reboot still cannot persist a BOOTTIME number alone because a new boot does not provide a portable continuation of the old origin.
Step 4: Handle Calendar Deadlines and Persistence Separately
“Daily at 09:00” is a calendar rule. It requires wall time, a named time zone, and a DST policy. A date's 09:00 may map to a different UTC offset after a rule change; some local times repeat or do not exist. Store the calendar expression and zone instead of converting it once at startup into a monotonic duration that is never recalculated. After one occurrence fires, monotonic timing can govern that run's execution timeout.
Audit data should store a normalized UTC instant, the original zone or offset when the business needs it, a record ID, and an authoritative commit order. Wall time is human-readable but neither unique nor strictly increasing. Equal or lower timestamps during an NTP rollback must not break a primary key, cursor, or balance order.
Step 5: Bound Cross-Process and Cross-Machine Propagation
An absolute monotonic reading is meaningful only in its defined runtime environment. Go's official documentation explicitly strips the monotonic reading during serialization. A protocol cannot send monotonic_deadline=8374921 to another host and ask it to compare directly; that host may have another origin, boot cycle, or API contract.
An RPC can propagate a bounded remaining budget or a UTC deadline, but the tradeoff must be explicit. Each hop spends the budget with a local monotonic clock and leaves headroom for transit, queueing, and skew. A high-risk lease cannot trust client time alone. Server authority, a lease epoch, and a fencing token decide whether writes remain valid.
Event ordering follows the same requirement-first method. A log UI may display wall time and flag suspected skew. Causality can use trace parents, message sequences, or logical clocks. A strict state-machine order uses a database commit position or consensus log. Sorting every event by created_at gives an observation order, not proof of real precedence.
Step 6: Turn Tests into Clock Invariants
Use an injectable clock or a platform time namespace/virtual clock in a test environment to cover:
- Step wall time forward by 90 seconds after 500 ms; the monotonic two-second timeout must not fire immediately.
- Step wall time backward by 90 seconds; the timeout still fires after roughly two elapsed seconds, while UTC logs may move backward without ID collision.
- Simulate gradual correction, verify no negative duration, and record the permitted measurement error.
- Suspend longer than a lease. A MONOTONIC task retains its defined budget; a BOOTTIME lease has expired.
- Restart the process. No old monotonic reading is restored; persisted expiration state is re-established according to its contract.
- Give two test nodes opposite clock offsets. The state machine still applies events by version or log position, not wall-clock magnitude.
- Simulate a DST gap and fold, then verify the explicit daily-09:00 policy.
At minimum, monitor negative-duration count, timeout error, early and late expiry, clock step/slew events, host offset, duplicate DST execution, and writes rejected by timestamp collisions. The 90-second offset is a fault-injection value, not a claim about production skew.
High-Quality Sample Answer
“This implementation puts three meanings into one CLOCK_REALTIME value. Wall time has to accept manual changes and synchronization. A forward step makes now - start suddenly exceed two seconds; a rollback makes the difference smaller or negative. I would calculate request durations and backoff within one monotonic time domain, preferably through a deadline API bound to that clock.
I would then split the other requirements. Audit records keep UTC wall time plus a stable record ID. Daily 09:00 keeps an IANA zone and an explicit DST policy. If a local lease must expire during suspend, Linux CLOCKBOOTTIME fits; if only runnable time counts, CLOCKMONOTONIC fits. Neither CPU time nor MONOTONIC_RAW is a drop-in replacement for an ordinary request timeout.
I would not store a monotonic reading in a database, send it to another host, or restore it across a restart. Cross-service logs can carry wall time for observation, but a version, message sequence, commit log, or logical clock owns business order. Each RPC hop spends a bounded budget with its local monotonic clock, while a security lease also uses server authority and fencing.
Finally, I would inject a 90-second forward step, a 90-second rollback, and gradual correction, then test suspend, process restart, two oppositely skewed nodes, and DST boundaries. Passing means no negative duration, no immediate or 90-second-late request timeout from a wall-clock step, the promised suspend behavior, and cross-host state order that is unchanged by physical skew.”
Common Mistakes
- Move every timestamp to a monotonic clock → monotonic values lack exchangeable calendar meaning and cannot express daily 09:00 → choose separately for durations, calendars, audits, and ordering.
- Continue subtracting
CLOCK_REALTIMEfor a timeout → a forward step expires early and a rollback expires late → compute start, deadline, and current time in one monotonic domain. - Claim monotonic time is entirely unaffected by NTP → Linux MONOTONIC avoids discontinuous steps but accepts gradual frequency adjustment → separate “never moves backward” from “perfectly uniform.”
- Assume
CLOCK_MONOTONICincludes suspend → Linux excludes suspended time → define suspend semantics first and use BOOTTIME when it must count. - Treat
CLOCKMONOTONICRAWas an upgraded default → bypassing clock discipline can make real-second measurement worse → use ordinary monotonic time for application timeouts and evaluate raw for low-level measurement. - Serialize a monotonic deadline to another host → the receiver has no portable shared origin → propagate a defined budget or UTC deadline, convert locally, and bound skew risk.
- Use
created_atas cross-host business order → skew and rollback can reverse events → put correctness in versions, commit positions, consensus logs, or logical clocks. - Test one manual clock change → slewing, suspend, restart, and DST remain uncovered → use an injectable-clock matrix and verify independent invariants.
Follow-Up Questions and Responses
Does gradual NTP correction make a two-second CLOCK_MONOTONIC interval inaccurate?
It can adjust the clock's rate slightly, but it does not produce the discontinuous rollback of a wall-clock step. Ordinary timeouts normally want a system-disciplined, nondecreasing clock whose seconds stay near real seconds, so that adjustment is appropriate. Clock-synchronization code, hardware benchmarking, or frequency analysis may evaluate CLOCKMONOTONICRAW and separately handle suspend and drift.
A lease must survive restart and expire while the machine is offline for a minute. What changes?
Do not persist an absolute local MONOTONIC or BOOTTIME value. The server stores a wall-time expiry instant, lease epoch, and fencing token, and the client revalidates with that authority after reconnecting. During one process run, the granted remaining budget can become a local BOOTTIME deadline. Even if an old process mistakenly believes its lease is live, the storage layer rejects its stale fencing token.
If both services use NTP, can millisecond timestamps determine event order?
No. Synchronization narrows uncertainty but does not prove causality between two physical readings, and network delay changes observation order. For log display, retain both values and surface uncertainty. To prevent an old state overwriting a new one, use a per-entity version, message sequence, database commit position, or logical clock. A global strict order requires a consensus or single-sequencer path.
Why not measure request latency with process CPU time?
A request may wait on the network, disk, a lock, or a connection pool. Those waits affect user latency while consuming almost no CPU. CPU time measures computational cost; an elapsed-time clock measures end-to-end latency and timeout. Both can be recorded, but they answer different questions.
How should daily 09:00 behave at a daylight-saving transition?
Define the product rule first. For a nonexistent local time, skip it or move to the next valid instant. For a repeated time, run once or once for each offset. Store the IANA zone and a deduplication key rather than only the current UTC offset. Once the next calendar occurrence is chosen, local waiting and execution timeout can still use monotonic time.