Instagram is one of the most popular photo-sharing app today, with around 1 billion monthly active users according to Statista. Similar services, such as Flickr, Picasa, Pinterest and Snapchat also have their fair share of following. The basic purpose of such apps is to upload and share pictures with other users but there are plenty of other features too, to keep the interests of the users alive.
If you were asked to design Instagram or a similar photo-sharing app in a system design interview, how will you go about it? Let's design a basic photo-sharing app that can support millions of users and handle the flow of an equally large number of photos daily.
Instagram allows people to upload pictures and videos and share them with other users. Similar to Twitter, users can also follow other users and like, share and comment on their posts. There's also a News Feed just like other social networking apps, with top posts from people.
Other than the basics, Instagram continually upgrades its services with the latest features. You'll often find new filters to try out new poses, backgrounds and looks. An interesting feature is Instagram Story that allows you to post your day's pictures and videos that your friends can see for 24 hours.
For a basic photo-sharing app, we'll include the following requirements in our design:
If you wish to extend the design and incorporate more advanced features, here are some suggestions:
Considering non-functional requirements is important in building a scalable system that can efficiently serve millions of users. Here are some of the characteristics that we will want in a scalable photo-sharing app.
Our photo-sharing app should be highly available, with minimum latency in developing News Feeds and viewing photos. As compared to availability, consistency is of secondary importance since it's acceptable if the photos or videos recently uploaded aren't immediately available to all the followers. So we're aiming for an eventually consistent system with high availability.
Even though uploaded photos may not immediately be available to other users on the network, the service should guarantee that once a photo is uploaded, it will not be lost.
Applications such as Instagram and Snapchat are read-heavy. Read requests to fetch News Feeds and display photos are much more than write requests to upload photos. We want a system that can handle a high number of reads each second.
Since Instagram deals with photos and videos and there are no limitations on the numbers of files users can upload, our system will need an efficient mechanism to store it.
Assuming there are 1 billion active users on Instagram and each user uploads 3 photos in a day, there will be 3 billion pictures uploaded each day.
If each picture takes 150 KBs of storage, we'll need about
of storage for pictures each day.
Let's assume Instagram stores files in its database for 5 years. The total storage we'll need is:
Pictures aren't the only items that are stored. Each picture will also carry metadata. In addition, user comments and a list of people that a user follows will also need to be stored. Even if we allocate a separate server to manage the database, it will not be able to store such a large size of data. To retrieve data faster and optimize performance, we will need an approach to scale the database.
Different scaling techniques may be used:
50% off Udemy courses
Grokking the System Design Interview
Java Multithreading for Senior Engineering Interviews
Grokking the Advanced Design Interview
Grokking the Coding Interview: Patterns for Coding Questions
Grokking Dynamic Programming Patterns for Coding Interviews
Coderust: Hacking the Coding Interview