Datadog logo

Datadog Hard Interview Questions

2 hard-level practice questions for Datadog technical interviews

Datadog software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer

No verified questions yet for Datadog.

coding Hard hash map #1

1. [Hash Map] — Match streaming logs against dynamically registered queries


Background
Datadog Log Management processes logs that engineers search to investigate incidents and monitor services. This exercise models the matching core of a live log subscription system: queries are registered before logs arrive, and each incoming log must be routed to the matching subscriptions.
Problem statement
Implement a LogQueryMatcher that processes query registrations, cancellations, and log messages in call order.
A token is a maximal contiguous sequence of ASCII letters or digits, normalized to lowercase. All other characters are separators. For example, ERROR: db-42 produces the tokens error, db, and 42.
A query matches a log if every distinct token in the query occurs somewhere in the log. Token order and repetition do not matter, and matching uses whole tokens rather than substrings. Thus, database timeout matches TIMEOUT connecting to database, but error does not match errors.
Each registration receives a unique, monotonically increasing integer ID, starting at 1. Identical queries registered separately receive different IDs and remain independent. A cancellation deactivates only the specified ID. For each log, return all matching active IDs in ascending order. Logs are not retained or matched against future registrations.
The query population is large, while most logs share tokens with only a small fraction of queries. Your implementation must use a searchable index rather than scan every active query for each log. Cancellation must also avoid scanning unrelated queries. Query cancellation is an extension to the reported registration-and-log-matching exercise.
Function or class signature
  • LogQueryMatcher() — construct an empty matcher.

  • register(query: str) -> int — register a query and return its new ID.

  • unregister(query_id: int) -> bool — deactivate an active ID and return true; return false if it is unknown or already inactive.

  • match(log: str) -> list[int] — return matching active IDs in ascending order.


Example 1:
Input:
[
  {"method": "register", "query": "database timeout"},
  {"method": "register", "query": "ERROR"},
  {"method": "register", "query": "timeout timeout"},
  {"method": "match", "log": "ERROR: database connection TIMEOUT"},
  {"method": "match", "log": "database errors"}
]
Output:
[1, 2, 3, [1, 2, 3], []]
Explanation: The first log contains every required token of all three queries. Repeated timeout tokens in query 3 count only once. The second log lacks timeout, and errors is not the token error.
Example 2:
Input:
[
  {"method": "register", "query": "api-500"},
  {"method": "register", "query": "500 API"},
  {"method": "match", "log": "api returned 500; API retry"},
  {"method": "unregister", "query_id": 1},
  {"method": "unregister", "query_id": 1},
  {"method": "match", "log": "API 500"},
  {"method": "register", "query": "api"},
  {"method": "match", "log": "api500"},
  {"method": "match", "log": "api"}
]
Output:
[1, 2, [1, 2], true, false, [2], 3, [], [3]]
Explanation: Queries 1 and 2 have the same token set but independent IDs. Cancelling query 1 leaves query 2 active. IDs are never reused. The token api500 is neither api nor 500, so it matches no active query.
Constraints:
  • At most 200,000 total method calls per matcher instance.

  • Each query contains 1–256 ASCII characters and at least one token.

  • Each log contains 0–10,000 ASCII characters; a log with no tokens matches nothing.

  • The total length of all query and log arguments is at most 20,000,000 characters.

  • The sum of distinct-token counts across active queries is at most 1,000,000.

  • Cancellation IDs are integers in the range 1 through 1,000,000,000.

  • Calls are sequential; thread safety is not required.


Follow-up:
A common token such as error now occurs in nearly every query and log, making its posting list expensive to visit. How would you index each query under one selected anchor token, verify candidates against their complete token sets, and choose or rebalance anchors as token frequencies change? Explain how you preserve correctness and what worst-case work remains unavoidable.
Want to practise this one?
Create a free account to open the full question and practise Datadog questions with AI.
Sign up free
coding Hard trie #2

2. [AI Enabled Coding] Query-Aware Log Ingestion Budgets


Scenario
Datadog Log Management processes logs from many services within each customer organization. Build a simplified ingestion-policy evaluator that matches log messages against literal queries and enforces rolling byte budgets, helping operators keep noisy services from consuming their indexing allowance. These are exercise-specific policies, not Datadog's actual billing rules; you may use an AI assistant while implementing and testing your solution.
Part 1 — Default service budgets
  • Each input record is a map with string keys and string values: id, timestamp_ms, organization, service, message, and bytes. bytes is the supplied ingestion weight, not the length of message.

  • Process records by increasing numeric timestamp_ms, breaking ties by their original input position. Return results in processing order.

  • Match queries as case-sensitive, contiguous literal substrings. A rule matches a record at most once, even if its query occurs repeatedly.

  • Install two default rules: error matches ERROR and allows 100 bytes per service per organization over 1000 ms; timeout matches timeout and allows 60 bytes per service per organization over 1000 ms.

  • For a matching rule with window W, usage at time t is the sum of bytes from previously accepted records matching that rule and scope with timestamps in (t − W, t]. Previously processed records at timestamp t count; a record exactly at t − W does not.

  • A record with no matching rules is ignored. Otherwise, reject it if current_usage + bytes > limit for any matching rule. Equality is allowed. An accepted record consumes its full byte weight in every matching rule; a rejected or ignored record consumes nothing.

  • For this stage, expose each record's ID and status: accepted, rejected, or ignored.


Function signature: evaluate_logs(logs: list[dict[str, str]]). The return type is up to you; the examples use JSON arrays of result objects.
Example 1:
Input:
{
  "logs": [
    {"id":"a","timestamp_ms":"0","organization":"acme","service":"api","message":"ERROR database","bytes":"60"},
    {"id":"b","timestamp_ms":"100","organization":"acme","service":"api","message":"ERROR timeout","bytes":"50"},
    {"id":"c","timestamp_ms":"200","organization":"acme","service":"api","message":"timeout upstream","bytes":"40"},
    {"id":"d","timestamp_ms":"300","organization":"acme","service":"api","message":"INFO healthy","bytes":"20"},
    {"id":"e","timestamp_ms":"1000","organization":"acme","service":"api","message":"ERROR timeout","bytes":"20"}
  ]
}

Output:
[
  {"id":"a","status":"accepted"},
  {"id":"b","status":"rejected"},
  {"id":"c","status":"accepted"},
  {"id":"d","status":"ignored"},
  {"id":"e","status":"accepted"}
]

Explanation: a consumes 60 error bytes. b would bring error usage to 60 + 50 = 110 > 100, so it consumes neither error nor timeout budget. c consumes 40 timeout bytes. d matches neither query. At time 1000, a has expired: e brings error usage to 20 and timeout usage to 40 + 20 = 60, so both limits pass.
Part 2 — Organization policies and explainable decisions
Other teams now need to install additional literal-query rules, including organization-wide budgets shared by different services. Extend, rather than replace, Part 1: both default rules always remain active.
  • Add evaluate_logs_with_rules(logs: list[dict[str, str]], additional_rules: list[dict[str, str]]). Each additional rule has string fields id, query, scope, limit_bytes, and window_ms. scope is either service or organization; a service scope is keyed by both organization and service, while an organization scope is keyed only by organization.

  • Apply the same matching, rolling-window, and all-or-nothing acceptance semantics to every rule. A record matching only an additional rule is eligible for acceptance. Each rule has an independent budget, even when two rules have identical queries.

  • Return every matching rule ID and all violations, rather than stopping at the first failure. Sort matched_rules and violations lexicographically by rule ID. Each violation contains rule_id, used_bytes before this record, attempted_bytes equal to used_bytes + record.bytes, and limit_bytes. Accepted and ignored records have an empty violations list.

  • Discuss how your return type changes before implementing this stage. Keep matching, scope selection, rolling accounting, and result formatting sufficiently separate to support future additions of these policy kinds without rewriting the evaluator.

  • Target up to 10,000 additional queries: scanning every query against every message is not an acceptable final approach. Explain your output-sensitive matching complexity, including repeated substring occurrences.


Example 2:
Input:
{
  "additional_rules": [
    {"id":"org_errors","query":"ERROR","scope":"organization","limit_bytes":"120","window_ms":"1000"}
  ],
  "logs": [
    {"id":"a","timestamp_ms":"0","organization":"acme","service":"api","message":"ERROR","bytes":"70"},
    {"id":"b","timestamp_ms":"100","organization":"acme","service":"worker","message":"ERROR","bytes":"40"},
    {"id":"c","timestamp_ms":"200","organization":"acme","service":"api","message":"ERROR","bytes":"20"},
    {"id":"d","timestamp_ms":"300","organization":"acme","service":"worker","message":"timeout","bytes":"50"},
    {"id":"e","timestamp_ms":"1000","organization":"acme","service":"api","message":"ERROR timeout","bytes":"30"}
  ]
}

Output:
[
  {"id":"a","status":"accepted","matched_rules":["error","org_errors"],"violations":[]},
  {"id":"b","status":"accepted","matched_rules":["error","org_errors"],"violations":[]},
  {"id":"c","status":"rejected","matched_rules":["error","org_errors"],"violations":[{"rule_id":"org_errors","used_bytes":110,"attempted_bytes":130,"limit_bytes":120}]},
  {"id":"d","status":"accepted","matched_rules":["timeout"],"violations":[]},
  {"id":"e","status":"accepted","matched_rules":["error","org_errors","timeout"],"violations":[]}
]

Explanation: a and b use different service budgets but together consume 70 + 40 = 110 organization error bytes. For c, the service error total would be 70 + 20 = 90, but the organization total would be 110 + 20 = 130 > 120; it is rejected without changing either budget. d consumes 50 timeout bytes only for worker. At time 1000, a expires: e produces service error usage 30, organization error usage 40 + 30 = 70, and api timeout usage 30.
Example 3:
Input:
{
  "additional_rules": [
    {"id":"org_errors","query":"ERROR","scope":"organization","limit_bytes":"120","window_ms":"1000"},
    {"id":"org_timeouts","query":"timeout","scope":"organization","limit_bytes":"50","window_ms":"1000"}
  ],
  "logs": [
    {"id":"a","timestamp_ms":"0","organization":"acme","service":"api","message":"ERROR timeout","bytes":"40"},
    {"id":"b","timestamp_ms":"100","organization":"acme","service":"worker","message":"ERROR","bytes":"80"},
    {"id":"c","timestamp_ms":"200","organization":"acme","service":"api","message":"ERROR timeout","bytes":"70"},
    {"id":"d","timestamp_ms":"1000","organization":"acme","service":"api","message":"ERROR timeout","bytes":"20"},
    {"id":"e","timestamp_ms":"1100","organization":"acme","service":"api","message":"ERROR timeout","bytes":"40"}
  ]
}

Output:
[
  {"id":"a","status":"accepted","matched_rules":["error","org_errors","org_timeouts","timeout"],"violations":[]},
  {"id":"b","status":"accepted","matched_rules":["error","org_errors"],"violations":[]},
  {"id":"c","status":"rejected","matched_rules":["error","org_errors","org_timeouts","timeout"],"violations":[{"rule_id":"error","used_bytes":40,"attempted_bytes":110,"limit_bytes":100},{"rule_id":"org_errors","used_bytes":120,"attempted_bytes":190,"limit_bytes":120},{"rule_id":"org_timeouts","used_bytes":40,"attempted_bytes":110,"limit_bytes":50},{"rule_id":"timeout","used_bytes":40,"attempted_bytes":110,"limit_bytes":60}]},
  {"id":"d","status":"accepted","matched_rules":["error","org_errors","org_timeouts","timeout"],"violations":[]},
  {"id":"e","status":"rejected","matched_rules":["error","org_errors","org_timeouts","timeout"],"violations":[{"rule_id":"org_timeouts","used_bytes":20,"attempted_bytes":60,"limit_bytes":50}]}
]

Explanation: a consumes 40 bytes in four independent budgets. b brings organization error usage to 40 + 80 = 120. c violates all four matching rules: 40 + 70 = 110 > 100, 120 + 70 = 190 > 120, 40 + 70 = 110 > 50, and 40 + 70 = 110 > 60. At time 1000, a expires, so d produces totals of 20 service-error bytes, 80 + 20 = 100 organization-error bytes, 20 organization-timeout bytes, and 20 service-timeout bytes. At time 1100, b expires; e would produce 60 bytes in each matching budget, exceeding only the organization-timeout cap of 50. Its rejection changes no budget.
Notes:
  • Inputs are valid ASCII strings; record IDs are unique, and additional rule IDs are unique and distinct from error and timeout. Queries are nonempty. Every function call starts with empty usage state.

  • There are at most 200,000 records and 10,000 additional rules, with at most 2,000,000 message characters and 200,000 additional-query characters in total. Timestamps are integers in [0, 10^15]; weights, limits, and windows are integers in [1, 10^9], encoded as strings.

  • This is a single-process batch problem. Input may be unsorted; distributed coordination, actual log parsing, and concurrent updates are out of scope.

Start practicing Datadog questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free