Instagram architecture & database

Instagram architecture & database

Instagram is the most popular photo-oriented social network on the planet today. With over a billion users, it has become the first choice for businesses to run their marketing campaigns on.

1. What technology does Instagram use on the backend?

The server-side code is powered by Django Python. All the web and async servers run in a distributed environment and are stateless.

Asynchronous Behavior

RabbitMQ and Celery handle asynchronous tasks such as sending notifications to the users and other system background processes.

Celery is an asynchronous task queue based on distributed message communication, focused on real-time operations. It supports scheduling too. The recommended message broker for celery is RabbitMQ.

RabbitMQ, on the other hand, is a popular open-source message broker written using the AMQP Advanced Messaging Queuing Protocol.

Gearman is used to distribute tasks across several nodes in the system and for asynchronous task handling such as media uploads, etc.?It’s an application framework for distributing tasks to other machines or processes that are more fit to execute those particular tasks. It has a gamut of applications ranging from highly available websites to the transport of database backup events.

Computing Trending Hashtags On The Platform

The trending backend is a stream processing application that contains four nodes/components connected linearly.

The role of the nodes is to consume a stream of event logs and produce the ranked list of trending content i.e. hashtags and places.

Pre-processor Node

The pre-processor node attaches the necessary data needed to apply filters on the original media that has metadata attached to it.

Parser Node

The parser node extracts all the hashtags attached to an image and applies filters to it.

Scorer Node

The scorer node keeps track of the counters for each hashtag based on time. All the counter data is kept in the cache, also persisted for durability.

Ranker Node

The role of the ranker node is to compute the trending scores of hashtags. The trends are served from a read-through cache that is Memcache and the database is Postgres.

Databases Used @Instagram

PostgreSQL is the primary database of the application, it stores most of the data of the platform such as user data, photos, tags, meta-tags, etc.

As the platform gained popularity and the data grew huge over time, the engineering team at Insta meditated on different NoSQL solutions to scale and finally decided to shard the existing PostgreSQL database as it best suited their requirements.

To get a deeper insight into distributed databases like how they handle concurrent traffic, data growth and such, check out my distributed systems design course – Design Modern Web-Scale Distributed Applications Like a Pro

Speaking of scaling the database via sharding and other means, this article YouTube database – How does it store so many videos without running out of storage space??is an interesting read.

The main database cluster of Instagram contains 12 replicas in different zones and involves 12 Quadruple extra large memory instances.

Hive is used for data archiving. It’s a data warehousing software built on top of Apache Hadoop for data query and analytics capabilities. A scheduled batch process runs at regular intervals to archive data from PostgreSQL DB to Hive.

Vmtouch, a tool for learning about and managing the file system cache of Unix and Unix-like servers, is used to manage in-memory data when moving from one machine to another.

Using Pgbouncer?to pool PostgreSQL connections when connecting with the backend web server resulted in a huge performance boost.

Redis an in-memory database is used to store the activity feed, sessions and other app’s real-time data.

Memcache an open-source distributed memory caching system is used for caching throughout the service.

Data Management in the Cluster

Data across the cluster is eventually consistent, cache tiers are co-located with the web servers in the same data center to avoid latency.

The data is classified into global and local data which helps the team to scale. Global data is replicated across different data centers across geographical zones. On the other hand, the local data is confined to specific data centers.

If you wish to understand how the cloud deploys workloads globally across availability zones and data centers, how clusters work, and more. Check out my platform-agnostic cloud computing course.

Initially, the backend of the app was hosted on AWS but was later migrated to Facebook data centers. This eased the integration of Instagram with other Facebook services, cut down latency and enabled them to leverage the frameworks, tools for large-scale deployments built by the Facebook engineering team.

Monitoring

With so many instances powering the service, monitoring plays a key role in ensuring the health and availability of the service.

Munin is an open-source resource, network and infrastructure monitoring tool used by Instagram to track metrics across the service and get notified of any anomalies.

StatsD a network daemon is used to track statistics like counters and timers. Counters at Instagram are used to track events like user signups, number of likes, etc.?Timers are used to time the generation of feeds and other events that are performed by users on the app. These statistics are almost real-time and enable the developers to evaluate the system and code changes immediately.

Dogslow a Django middleware is used to watch the running processes and a snapshot is taken of any process taking longer than the stipulated time by the middleware and the file is written to the disk.

Pingdom is used for the website’s external monitoring, ensuring expected performance and availability.?PagerDuty is used for notifications & incident response.

How Does Instagram Runs A Search For Content Through Billions of Images?

Instagram initially used Elasticsearch for its search feature but later migrated to Unicorn, a social graph-aware search engine built by Facebook in-house.

Unicorn powers search at Facebook and has scaled to indexes containing trillions of documents. It allows the application to save locations, users, hashtags, etc and the relationship between these entities.

Speaking of Insta’s search infrastructure, it has denormalized data stores for users, locations, hashtags, media, etc.

These data stores can also be called documents, which are grouped into sets to be processed by efficient set operations such as AND-OR and NOT.

The search infrastructure has a system called Slipstream which breaks the user uploaded data, streams it through a Firehose and adds it to the search indexes.

The data stored by these search indexes is more search-oriented as opposed to the regular persistence of uploaded data to PostgreSQL DB.


要查看或添加评论,请登录

NISHI KUMARI的更多文章

  • Row-level security (RLS)

    Row-level security (RLS)

    Create roles It's possible to create multiple roles. When you're considering the permission needs for a single report…

  • What is NULL ?

    What is NULL ?

    In Structured Query Language Null Or NULL is a special type of marker which is used to tell us about that a data value…

  • Delta Format

    Delta Format

    The Delta format is a storage format used in data lakes, particularly in the context of Azure Data Factory and Azure…

  • Amazon SageMaker

    Amazon SageMaker

    Amazon SageMaker is a fully managed machine learning (ML) service provided by Amazon Web Services (AWS). It enables…

  • What is SharePoint?

    What is SharePoint?

    SharePoint is a web-based collaborative platform developed by Microsoft, launched in 2001. It is primarily used for web…

  • What is Data Pipeline?

    What is Data Pipeline?

    A data pipeline is a series of processes and tools designed to collect, process, and deliver data from various sources…

  • What is Azure Logic Apps?

    What is Azure Logic Apps?

    Azure Logic Apps, from Microsoft Azure, is a cloud-based Platform-as-a-Service (PaaS) that is used to automate tasks…

  • What is Power Automate

    What is Power Automate

    Microsoft Power Automate is a comprehensive cloud-based automation platform designed to streamline and optimize…

  • Campaign Optimization Techniques

    Campaign Optimization Techniques

    Campaign optimization is a crucial aspect of any marketing strategy, whether it be for a small business or a…

  • What is Account Management?

    What is Account Management?

    Account management is a post-sales role that focuses on nurturing client relationships. Account managers have two…

社区洞察

其他会员也浏览了