Activity Tag Logging System

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-03-29

Problem Statement

Design the low-level architecture for an Activity Tag Logging System that allows systems or users to log activities with rich tags/metadata, and later query or filter them based on those tags.


This system is commonly used for:

•Internal observability
•Feature usage tracking
•Behavioral analytics
•Debugging/auditing


🔷 Functional Requirements:

1.Log Activity:
•Clients (internal services or users) can log an activity event with:
•Activity name (string)
•Timestamp
•Actor (user ID or service ID)
•List of key-value tags (e.g., {“feature”: “chat”, “env”: “prod”})
•Optional payload or metadata
2.Query Activities:
•Filter logs based on:
•Time range
•Tag values (e.g., feature=chat)
•Actor ID
•Activity name
3.Tag-Based Filtering:
•Support exact match and partial match on tag values.
•Allow logical operations like AND, OR.
4.Update/Delete Log Entry (Optional):
•Allow certain privileged actors to edit or remove past logs.
5.Export Logs:
•Provide export in JSON or CSV format.


🔷 Constraints & Assumptions:

•Tags are unbounded in number and arbitrary in name/value.
•Payload is stored as a blob (can be ignored for logic).
•No real persistence or UI required — simulate in-memory storage.
•No authentication/authorization logic needed.
•Support idempotent log insertion via client-provided log_id (optional).


🔶 Expected Design Focus:

•Core classes: Activity, Tag, LoggerService, QueryEngine
•Data structure for storing and querying logs efficiently
•Use of composition for tag management
•Design for extensibility — allow for adding new filters or log types
•Clean abstraction between logging and querying
•Apply OOP principles (especially SRP, OCP)


🔷 Bonus (Optional):

•Add tag hierarchy or tagging conventions (e.g., namespace support)
•Add rate-limiting or batching for ingestion
•Add TTL (time to live) support for expiring logs


✅ Sample Use Case:

1plaintext 2CopyEdit 31. Log: 4 - Activity: “UserLogin” 5 - Actor: user_123 6 - Tags: {"platform": "web", "region": "us-east", "feature": "auth"} 7 - Timestamp: now 8 92. Query: 10 - Return all logs where `feature = auth AND platform = web` in last 7 days.


Solution

Comments