← Questions

Filter and analyze logs with an object-oriented design

0
AmazonOO designLast asked Sep 2025

An object-oriented design interview question asked in Amazon's technical phone screen, last asked Sep 2025. It tests object-oriented design, logs and filtering.

Design the classes of a log-processing service. It reads a stream of application log entries (time, service, host, level, message) and answers three kinds of query: filter the entries by attributes, count the error-level entries in a time window, and build an hourly histogram of entries that match a pattern. New filters and new reports must be easy to add. Then explain how the design holds up when logs arrive at very high volume.

Requirements

  • Functional: filter(query) by service, level, host, time range and a substring or regular expression on the message; count_errors(window, predicates) for ERROR and above; histogram_by_hour(query, window) returning a count per hour bucket; new filter types and new reports without changing existing classes.
  • Non-functional: queries over recent data in seconds; late, duplicated and out-of-order entries handled correctly; old data kept cheaply.

Clarifying questions

  • How many entries a second, and how far back must queries reach?
  • Does a histogram bucket by the time the entry was logged or the time it arrived?
  • Must the counts be exact, or is a small error acceptable for fast answers?
  • Which time zone are hourly buckets in?

What a strong answer covers

  • Classes: LogEntry; a Filter interface with matches(entry) and implementations (LevelFilter, ServiceFilter, TimeRangeFilter, MessagePatternFilter) combined with AndFilter and OrFilter; a Report or aggregator interface (ErrorCount, HourlyHistogram) fed the filtered entries; a LogQueryService that plans and runs a query. New filters and reports are new classes, not edits.
  • Parsing and validation at ingestion, deduplication by an entry id, and assigning entries to buckets by their own timestamp, with a watermark that decides when a past hour is final.
  • At scale: storage partitioned by time and service, hourly rollups computed on write for the counts and histograms, an inverted index for message search, and hot, warm and cold tiers with retention.
  • The trade-off between rollups (fast, fixed questions) and scanning raw entries (flexible, slow), with the cost of each query type.

Follow-ups

  • Add a report of the ten most frequent error messages per hour.
  • A service starts logging ten times more. What protects the rest?
  • Alert when the error count in the last five minutes exceeds a threshold.

Where it's asked

  • Amazon · Technical phone screen · Last asked Sep 202560 min · Live coding in a shared editor that does not run code, plus Leadership Principles questions · No AI

What it tests

object-oriented design · logs · filtering

Your canvas
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing