Group Production Log Messages by Template by Masking Variable Fields

Last updated: November 29, 2026

Quick Overview

Given raw log messages from a service, derive a template for each by masking variable parts (UUIDs, IP addresses, hex values, numbers with units, quoted strings) and return the k most frequent templates with their counts.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given raw log messages from a service, derive a template for each by masking variable parts (UUIDs, IP addresses, hex values, numbers with units, quoted strings) and return the k most frequent templates with their counts.

Google SREs triaging an incident in Cloud Logging want the error patterns, not ten thousand near-identical lines. The interviewer checks that you choose masking rules in the right order (specific before generic), avoid over-masking identifiers like sda1 or v2, and produce deterministic top-k output.

What the Interviewer Expects
  • Defines which variable fields to mask and their precedence
  • Applies specific patterns such as UUID and IP before generic numbers
  • Avoids masking digits that are part of identifiers
  • Counts templates with a hash map and breaks ties deterministically
  • Discusses learning templates automatically when rules are not enough
Key Topics to Cover
Regular Expressions
Log Analysis
Hash Map Counting
Top-K
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Messages have no obvious delimiters for variables; how would you learn templates automatically (for example, by clustering token positions)?
  • Compute templates in a streaming job with bounded memory for the top k.
  • How would you alert when a brand-new template appears during a deploy?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of log lines and k.
  • Masking rules: UUID to <UUID>, IPv4 with optional port to <IP>, 0x... to <HEX>, standalone numbers with optional unit (ms, s, kb, mb) to <NUM>, ...
High-Level Design

Apply an ordered list of regex substitutions to each line. Order matters: masking numbers first would destroy UUIDs and IPs before their own rules could match them. The number rule uses a negative loo...


Submit Your Answer
Markdown supported