User Management:
Photo Upload and Management:
Newsfeed:
Search Functionality:
Notifications:
Privacy and Security:
Engagement:
Performance:
Scalability:
Availability:
Security:
Data Retention:
Usability:
Reliability:
Compliance:
photo_id.photo_id and removes it from storage.follower_id and followee_id.photo_id.usersuser_id (Primary Key, INT)username (VARCHAR, unique)email (VARCHAR, unique)password_hash (VARCHAR)profile_picture_url (VARCHAR, nullable)bio (TEXT, nullable)followers_count (INT)following_count (INT)created_at (DATETIME)updated_at (DATETIME)photosphoto_id (Primary Key, INT)user_id (Foreign Key, INT, references users)caption (TEXT, nullable)location (VARCHAR, nullable)photo_url (VARCHAR)created_at (DATETIME)updated_at (DATETIME)commentscomment_id (Primary Key, INT)photo_id (Foreign Key, INT, references photos)user_id (Foreign Key, INT, references users)text (TEXT)created_at (DATETIME)likeslike_id (Primary Key, INT)photo_id (Foreign Key, INT, references photos)user_id (Foreign Key, INT, references users)created_at (DATETIME)followsfollower_id (Foreign Key, INT, references users)followee_id (Foreign Key, INT, references users)created_at (DATETIME)notificationsnotification_id (Primary Key, INT)user_id (Foreign Key, INT, references users)type (VARCHAR, e.g., like, comment, follow)message (TEXT)is_read (BOOLEAN)created_at (DATETIME)search_indexindex_id (Primary Key, INT)photo_id (Foreign Key, INT, references photos)hashtags (TEXT, array or list)tags (TEXT, array or list)created_at (DATETIME)media_storagemedia_id (Primary Key, INT)photo_id (Foreign Key, INT, references photos)file_url (VARCHAR)file_type (VARCHAR, e.g., image/jpeg)created_at (DATETIME)The Client is the user interface of the Instagram-like Photo Sharing Platform. It allows users to interact with the platform, upload photos, browse the newsfeed, like and comment on posts, and follow other users. The client can be a web application or a mobile app. It communicates with the backend services through the API Gateway to fetch data, interact with photos, and manage user profiles.
The Load Balancer distributes incoming traffic to multiple instances of the API Gateway, ensuring that the system can handle high traffic efficiently. It prevents any single server from becoming a bottleneck and improves fault tolerance by rerouting traffic to healthy servers if one becomes unavailable.
The API Gateway acts as the central entry point for client requests. It routes requests to the appropriate backend services, handles authentication, validates requests, and aggregates responses. The API Gateway also enforces security measures like rate limiting and manages cross-origin requests.
The Authentication Service is responsible for managing user registration, login, and session handling. When a user logs in with their credentials, the service verifies them against the database and returns a JWT token that the client uses for future requests to authenticate the user. It also handles password resets and user sessions.
The Photo Service manages the core functionality of uploading, storing, and interacting with photos. Users can upload new photos, edit captions, tag photos with hashtags, and associate metadata with each photo. The service also handles comments and likes for each photo and stores them in the relevant database.
The Notification Service is responsible for sending notifications to users when they receive likes, comments, or when they are followed by other users. It ensures that users are kept up to date with activities related to their photos. Notifications are cached in Redis to ensure low-latency access.
The Search Service enables users to search for photos, hashtags, and users. It uses Elasticsearch to index photo metadata, hashtags, and user data, allowing users to perform fast, efficient searches. This is especially important for an image-heavy platform where users often need to search for specific content quickly.
The User Service manages user profiles, including personal information, privacy settings, and user interactions (e.g., following other users). It tracks user activities and relationships, such as who they follow and who follows them. It also handles user preferences and account settings.
The Analytics Service tracks user interactions and engagement, providing insights into how users are interacting with photos and other content. It collects data about likes, comments, shares, and views, aggregates it in real-time with Kafka, and stores it in DynamoDB for real-time metrics. Long-term metrics are stored in PostgreSQL.
AWS S3 is used to store photos and other media files, while CloudFront CDN is used to deliver media to users quickly. S3 provides scalable, durable storage, while CloudFront ensures low-latency, high-performance delivery of media content worldwide.
Redis is used for caching frequently accessed data such as user sessions, notifications, and feed data. By caching this data, the system can reduce the load on the databases and deliver faster responses to the client.
PostgreSQL vs NoSQL: Chose PostgreSQL for user data, photo metadata, likes, and comments to maintain strong data consistency and support complex queries. NoSQL (like DynamoDB) is used for real-time analytics due to scalability.
S3 for Media Storage vs DB: Used S3 for storing photos instead of a database due to better scalability and cost-efficiency for large file storage.
Redis for Caching vs DB: Redis caches notifications and session data for faster access, reducing load on the database and improving performance.
Microservices vs Monolithic: Chose microservices for better scalability and isolation of components, though more complex than a monolithic approach.
Elasticsearch vs Relational DB for Search: Elasticsearch is used for efficient, fast search across unstructured data (hashtags, captions), whereas a relational DB would struggle with complex search queries.
WebSockets vs HTTP for Notifications: Chose HTTP polling over WebSockets to simplify implementation and improve scalability, though WebSockets are better for real-time communication.
AWS vs Self-Hosting: AWS provides managed infrastructure (S3, EC2, CloudFront), reducing operational overhead and offering scalable storage and CDN options.
Monitoring with CloudWatch: Used AWS CloudWatch for monitoring and logging instead of building custom solutions, as it integrates well with AWS services and scales automatically.
Database Overload: High traffic can overwhelm PostgreSQL, leading to slow queries.
Network Latency: Poor network conditions could degrade the performance of WebRTC or media delivery.
Cache Invalidation: Stale or inconsistent data in Redis can cause users to see outdated notifications or feed data.
Search Slowdown: Elasticsearch might slow down with a high volume of search queries or complex queries.
Notification Delays: High volume of notifications can overwhelm the Notification Service.
Media Delivery Failures: S3/CloudFront may face issues due to high load or server failures.
API Gateway Bottleneck: High traffic can overload the API Gateway, slowing down request processing.
Authentication Failures: Overload on the Authentication Service may lead to delays in token validation.
These improvements enhance scalability, reduce latency, and ensure system resilience during failure scenarios.