The interview problem

Practice prompt

GPS observations oscillate near a boundary and produce repeated arrival notifications. Design a geofence state machine.

Original practice, not a reported company interview. Scenarios and numbers are illustrative. Interview date: not applicable. Sources retrieved October 1, 2026.

1. Scope and worked approach

Assume user-authorized location observations with timestamps and accuracy estimates. Maintain outside, candidate-entry, inside and candidate-exit states per device/fence version. Use dwell time and spatial hysteresis before transitions, reject stale observations and retain an explicit uncertain state when accuracy is too poor. Give each confirmed transition a stable event ID for downstream deduplication. Expire stale device state rather than infer continuous presence forever.

2. Trace the design or derivation

Validate observation
  → assess accuracy
  → update candidate state
  → satisfy dwell
  → emit transition

Store the geometry version used for every emitted event. If a business later disputes an arrival, this allows replay under the original rule. Do not expose precise location histories to consumers that need only an arrival event; minimize both payload and retention while preserving the necessary audit evidence.

3. Calculate the example

With entry radius 90 m and exit radius 110 m around a nominal 100 m fence, observations at 98,102,99 and 101 m do not force repeated transitions under the hysteresis policy. A 40 m accuracy radius may still make either classification unjustified.

4. Failure cases and trade-offs

Long dwell reduces false alarms but delays genuine arrival. Sparse sampling can miss brief visits; more frequent location updates consume battery. Changing a fence definition needs a policy for existing inside states, not a silent replay of old coordinates against new geometry.

5. Validation, follow-ups and self-review

Replay boundary jitter, out-of-order points and long gaps. Follow-up: how do you define a visit that occurs between samples? Self-review: separate observed transition, inferred presence and uncertainty.

Sources and related practice

Technical reference: developer.android.com — Geofence transition and dwell concepts; example thresholds are illustrative.

Source publication/update: Not established. Retrieved October 1, 2026. The workflow, calculations and review exercises are original; this reference is not evidence that a company asked this question.

Continue with Find nearby available resources at scale; Design a notification delivery service.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.