Image by rawpixel.com on Freepik
In our previous post, we explored various API types, discussed seamless integration techniques, and delved into best practices for maintaining and scaling APIs. In this article, we will take a practical approach by designing the initial system for our API.
Imagine we’re building an app similar to Instagram. For simplicity, we’ll focus on basic functionalities such as user authentication, following other users, uploading pictures, and viewing a photo feed.
Functional Requirements:
- User registration
- User login/logout
- User follow/unfollow functionality
- Picture uploading capability
- Photo feed viewing option
Non-Functional Requirements:
- Maximum uptime
- Quick image loading with tolerance for delays
- Maximum durability and reliability
- High availability and scalability
Now, let’s outline the components needed to fulfill these requirements and sketch a high-level design.
- Application Server: Exposes APIs for consumption.
- Image Storage: Stores uploaded images.
- Data Storage: Stores user information and metadata.
- Messaging Queue: Facilitates communication between components.
- Load Balancers: Ensures even distribution of traffic.
Capacity Estimations:
Considering user base of 500 million, with 1 million active users daily, we estimate for the next 5 years:
- Total data generated per day: 1 million daily active users * 10 MB per user = 10,000,000 MB per day
- Total data generated per year: 10,000,000 MB per day * 365 days = 3,650,000,000 MB per year
- Total data generated for 5 years: 3,650,000,000 MB per year * 5 years = 18,250,000,000 MB
So, the total storage needed for 5 years would be 18,250,000,000 megabytes.
So for the image storage capacity, lets consider there are 25 images uploaded every second, and maximum image size allowed is 2 MB
- Total data generated per second: 25 images per second * 2 MB per image = 50 MB per second
- Total data generated per year: 50 MB per second * 60 seconds * 60 minutes * 24 hours * 365 days = 1,576,800,000 MB per year
- Total data generated for 5 years: 1,576,800,000 MB per year * 5 years = 7,884,000,000 MB
So, the total storage required for the next 5 years would be approximately 7,884,000,000 megabytes.
To ensure a smooth user experience, we’ll store resized images for slower network connections.
Detailed System Design:
Our services will include:
- Authentication Service: Handles user authentication.
- Feed Generation Service: Generates user feeds.
- Upload Service: Manages picture uploads.
- User Service: Manages user-related operations.
- AWS EKS: Orchestrates containerized applications.
- AWS API Gateway: Manages API endpoints.
- AWS S3: Provides scalable object storage.
- PostgreSQL: Serves as the relational database.
With this system design in place, we’ll further refine our database model and identify the necessary API endpoints in the next article.
Stay tuned for more insights into building robust API systems for your applications!
Leave a Reply