Design APIs to Post & Delete Messages on Multiple Social Platforms (LLD/API Design)
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-06-02
Problem Statement
Design a system that allows users to post and delete messages across multiple social media platforms (e.g., Twitter, Facebook, Instagram) using a unified set of APIs. The focus is on OOP design, API modeling, and extensibility for multiple platforms.
Functional Requirements
1.Post Message
•Users can post messages to one or more social media platforms.
•Each message may include: text, media attachments (images, videos), hashtags, mentions.
•The system should return a platform-specific message ID for tracking.
2.Delete Message
•Users can delete a previously posted message using the platform-specific message ID.
•Ensure deletion is propagated to the correct platform.
3.Multi-Platform Support
•System should support multiple platforms with different APIs.
•Adding a new platform should require minimal code changes.
4.Error Handling
•Handle API failures gracefully.
•Retry failed requests based on configurable policies.
•Log successes and failures for monitoring.
5.Optional Features
•Schedule posts for future timestamps.
•Fetch post status or engagement metrics.
Non-Functional Requirements
•Extensibility: Easy to add new platforms without changing existing APIs.
•Consistency: Ensure that message IDs and statuses are correctly mapped per platform.
•Thread Safety: Support concurrent posting/deletion.
•Testability: Clear separation of platform-specific implementations for unit testing.
Design Hints
•Key Classes / Interfaces:
•Message → represents the content, attachments, metadata.
•SocialPlatform (interface/abstract class) → defines methods postMessage(message) and deleteMessage(messageId).
•TwitterPlatform → implements SocialPlatform.
•FacebookPlatform → implements SocialPlatform.
•InstagramPlatform → implements SocialPlatform.
•SocialPlatformFactory → returns the correct SocialPlatform instance.
•MessageService → orchestrates posting/deleting messages across multiple platforms.
•MessageIdMapping → maps internal message IDs to platform-specific IDs.
•Design Patterns:
•Strategy Pattern → encapsulate platform-specific posting/deletion logic.
•Factory Pattern → create platform instances dynamically.
•Observer Pattern (Optional) → notify monitoring/logging systems about post success/failure.
Example Flow
1.User wants to post "Hello World!" to Twitter and Facebook.
2.MessageService receives request → iterates over platforms:
•Calls TwitterPlatform.postMessage(message) → returns twitterId123
•Calls FacebookPlatform.postMessage(message) → returns fbId456
3.Internal mapping stores {internalId: {Twitter: twitterId123, Facebook: fbId456}}.
4.User deletes the message:
•MessageService.deleteMessage(internalId) → invokes platform-specific deleteMessage methods.
Evaluation Areas
•Clean OOP modeling of message and platform abstractions.
•Correct use of design patterns for extensibility.
•Handling concurrent API calls and failures.
•Mapping internal vs platform-specific IDs.
•Extensibility to support new platforms in the future.