Design Tagging Service
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2024-06-30
Problem Statement
Design a Tagging Service that allows users and services to associate, search, and manage tags across various resources (documents, posts, products, events, users, etc.). This system should be scalable, extensible, and support fast read and write operations.
🔶 Functional Requirements
1.Tag Management
•Create, update, and delete tags
•Tags can be hierarchical (e.g., tech > AI > LLM) or flat
•Tags can be public (global) or scoped (user-specific or domain-specific)
2.Tag Association
•Associate tags to resources (documents, users, products, etc.)
•Bulk tagging support
•Assign metadata to tags (e.g., confidence score, tagging time, tagged by whom)
3.Tag Search & Retrieval
•Retrieve all tags for a resource
•Search resources by one or more tags (AND/OR)
•Autocomplete or suggest similar tags during input
4.Tag Recommendation (Optional)
•Suggest tags based on resource content
•Support machine learning models or rule-based inference
5.Access Control
•Only owners/editors of a resource can modify its tags
•Public tags should be searchable by all
6.Audit Logging (Optional)
•Track who added/removed tags and when
🔶 Non-Functional Requirements
•Low-latency reads for tag queries and search
•Should scale to support millions of resources and tens of millions of tags
•Highly available and consistent for mission-critical systems (e.g., search indexing)
•Should support multi-tenancy (different apps or clients)
🔷 System Constraints
•A single resource can have up to 100 tags
•Tags can be reused across resources and users
•Should support eventual consistency in tag suggestions
•Must support fast autocomplete with prefix match
🔶 Design Expectations
The HLD should cover the following components:
1.API Layer
•CRUD operations for tags
•APIs for tagging/untagging resources
•Search and autocomplete APIs
2.Tag Indexer
•Maintains reverse mappings from tags → resource IDs
•Should support efficient AND/OR queries
3.Storage Design
•Tag metadata: Relational DB (PostgreSQL/MySQL)
•Tag-to-resource mapping: Wide-column DB (e.g., Cassandra), Elasticsearch, or Redis for fast lookup
•Resource-to-tag mapping: Inverted index
4.Suggestion Engine (Optional)
•NLP-based content processing for auto-tagging
•Popular tags per domain/user
5.Search Engine
•Elasticsearch or Solr for full-text tag search
•Trie or Prefix tree for tag autocomplete
6.Cache Layer
•Frequently accessed tags and suggestions cached via Redis/Memcached
7.Access Control Service
•Ensures tagging privileges are respected
•Role-based permission check
8.Background Workers
•Batch processing for tag recommendations
•Index rebuilding, garbage collection of unused tags
🔷 Optional Features
•Tag ranking based on frequency/popularity
•Graph-based tag relationship viewer (e.g., tag co-occurrence)
•Support for multilingual tags
•Tag synonyms or aliases (e.g., "AI" = "Artificial Intelligence")