System Design Notes
Don’t forget to get your copy of Designing Data Intensive Applications the single most important book to read for system design interview prep!

Instagram/ Snapchat/ Flickr/ Picasa Design

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.

What Does A Basic Photo-Sharing App Do?

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.

List Down The Requirements

For a basic photo-sharing app, we'll include the following requirements in our design:

  • Users should be able to upload and view photos.
  • Users can follow any number of users.
  • Users can view News Feeds with posts from the users they follow.

Extended Requirements

If you wish to extend the design and incorporate more advanced features, here are some suggestions:

  • Users can comment and like photos.
  • Users can send and receive messages from other users.
  • Customized recommendations to connect with other other users based on the user's interests.
  • Users can add tags to pictures. Users can also be tagged on photos.

Characteristics Of A Photo-Sharing App

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.

High Availability, Eventual Consistency

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.

Reliability

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.

Read-Heavy

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.

Efficient Storage

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:

  • Vertical splitting, or partitioning, to partition database based on types of data, such as user database, image database, comment database etc.
  • Horizontal splitting, or sharding may also be used to split storage over different machines.

Click here to continue reading this lesson on Medium.