Design content moderation system for posts violating LinkedIn guidelines (open-ended with assumptions)
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-11-08
Problem Statement
Designing a content moderation system for a social platform (like LinkedIn) to detect and handle posts that violate platform guidelines. The focus is on scalable design, modular components, extensibility, and decision-making logic.
✅ Functional Requirements
1.Post Submission
•Users submit posts with text, images, or links.
•Each post has metadata: postId, userId, timestamp, contentType, content.
2.Moderation
•Detect violations based on:
•Offensive language or hate speech
•Spam or repeated content
•Malicious links or phishing attempts
•Copyright violations
•Classify post as: APPROVED, REVIEW_PENDING, REJECTED.
3.Workflow
•Automated moderation: apply rule-based and ML-based checks.
•Manual review: posts flagged as suspicious go to human moderators.
•Notifications sent to users for post rejection or action required.
4.Audit & Logging
•Maintain logs of moderation decisions and actions for compliance.
•Keep historical data for analytics and model training.
5.Performance & Scalability
•Handle millions of posts per day.
•Support low-latency moderation for near real-time approval.
6.Extensibility
•Easy to add new rules, ML models, and content types (video, documents).
•Support multi-language text detection.
🔐 Constraints & Assumptions
•Focus on LLD, modular design, and decision workflow; distributed scaling is optional.
•ML models for content violation detection can be treated as black boxes.
•Users and moderators may interact via APIs or dashboards.
•Assume posts are immutable once submitted, moderation results can be updated.
🧱 Key Components & Classes
1.Post Class
1
2class Post {
3public:
4 string postId;
5 string userId;
6 DateTime timestamp;
7 string contentType; // TEXT, IMAGE, LINK
8 string content;
9 string status; // APPROVED, REVIEW_PENDING, REJECTED
10};1.ModerationRule Interface / Abstract Class
1
2class ModerationRule {
3public:
4 virtual bool evaluate(Post post) = 0;
5};1.Concrete Moderation Rules
•Examples: OffensiveLanguageRule, SpamDetectionRule, LinkSafetyRule.
1
2class OffensiveLanguageRule : public ModerationRule {
3public:
4 bool evaluate(Post post) override;
5};1.ModerationEngine Class
•Core engine that evaluates posts against rules.
1
2class ModerationEngine {
3private:
4 vector<ModerationRule*> rules;
5public:
6 void addRule(ModerationRule* rule);
7 string moderate(Post post); // returns APPROVED, REVIEW_PENDING, REJECTED
8};1.PostRepository Class
•Stores posts and moderation results.
1
2class PostRepository {
3public:
4 void savePost(Post post);
5 Post getPost(string postId);
6 void updatePostStatus(string postId, string status);
7};1.NotificationService Class
•Sends updates to users when posts are rejected or require action.
🔄 Example Workflow
1.User submits a post → saved in PostRepository.
2.Post sent to ModerationEngine.
3.Engine evaluates post against rules:
•Passes all rules → APPROVED.
•Fails rule → REVIEW_PENDING or REJECTED.
4.If REVIEW_PENDING, human moderator reviews → updates status.
5.NotificationService informs the user of moderation results.
6.Logs stored for auditing and analytics.
🧪 Expected Deliverables
•Class diagram showing Post, ModerationEngine, ModerationRule, PostRepository.
•Implementation of rule evaluation and workflow.
•Test cases:
•Post flagged for offensive language
•Post flagged for spam
•Post approved automatically
•Status updates and notifications working correctly
💡 Discussion Points / Trade-offs
1.Automated vs Manual Moderation
•Fully automated: fast but may have false positives/negatives.
•Manual review: accurate but resource-intensive.
2.Performance vs Accuracy
•Real-time moderation may reduce accuracy if ML models are approximated.
•Batch processing improves accuracy but increases latency.
3.Extensibility
•System should allow adding new rules or models without major refactoring.
4.Scalability
•Partition posts by user, region, or content type for concurrent moderation