KatInterview

Design a Multi-Tenant Security Event Enrichment Engine

Data Structure DesignModel answer
MediumModel answerData Structure Designdesignobject-orientedmulti-tenancy

Last updated

Design and implement an in-memory pipeline to enrich telemetry events and evaluate dynamic suppression rules with multi-tenant scoping and fault tolerance.

You are building an in-memory security telemetry processing engine. The engine ingests streaming security events (such as login requests, administrative actions, or network connections), enriches them with threat context, and filters out non-critical alerts using rule-based suppression.

Engine Requirements

  1. Event Data Structure: Contains fields: tenant_id (str), event_type (str), timestamp (int), and attributes (dict).

  2. Extensible Component Interfaces:

    • Enricher: Defines an enrich(event: Event) -> None method that mutates event.attributes in place or appends context metadata.
    • SuppressionRule: Defines a should_suppress(event: Event) -> bool method that returns True if the event should be dropped.
  3. SecurityPipeline Execution Engine:

    • register_enricher(enricher: Enricher, tenant_id: Optional[str] = None) -> None: Registers an enricher globally (if tenant_id is None) or for a specific tenant.
    • register_suppression_rule(rule: SuppressionRule, tenant_id: Optional[str] = None) -> None: Registers a suppression rule globally or for a specific tenant.
    • process(event: Event) -> Optional[Event]: Executes applicable enrichment and suppression logic in two distinct phases:
      • Phase 1: Enrichment: Execute all applicable global enrichers in order of registration, followed by all tenant-specific enrichers in order of registration.
      • Phase 2: Suppression: Evaluate all applicable global suppression rules in order of registration, followed by tenant-specific suppression rules in order of registration.
      • If any suppression rule returns True, immediately stop evaluating further rules and return None. If all suppression rules pass without suppressing, return the modified Event.

Fault Isolation & Edge Cases

  • Enrichment Resilience: If an enricher raises an exception, catch the error, record an entry under event.attributes["pipeline_errors"], and continue executing remaining enrichers. Do not allow plugin exceptions to crash the pipeline.
  • Suppression Resilience: If a suppression rule raises an exception, log/record the error and treat the rule evaluation as False (fail-open) so legitimate alerts are not dropped by buggy rules.
  • Duck Typing: Accept any object implementing the required method signature (enrich or should_suppress), even if it does not explicitly inherit from the base interface.

Hints

Hint 1

Use separate lists for global plugins and dictionary-backed lists (keyed by tenant_id) for tenant-scoped plugins to preserve registration order while guaranteeing O(1) tenant lookup.

Hint 2

Execute all enrichers to completion before commencing the suppression phase so that suppression rules evaluate fully-populated event attributes.

Hint 3

Isolate plugin execution with try-except blocks, recording failures in event.attributes['pipeline_errors'] to ensure non-blocking pipeline operations.