As you might have known,
Instagram is selling Facebook for $ 1 billion . Many have a question: For what kind of money? Someone on Habré compared it with the dot-com boom. Yes, but all this boom on one Facebook and holds.
For two years, CEO Instagram Kevin Systrom was thinking about how to monetize his fast-growing offspring, but he never figured it out. At the same time, many times there were rumors about his refusal to deal with Facebook. The Google autosupport has long given the phrase “Kevin Systrom net worth” to the query “kevin systrom” for a long time. Things went uphill without Facebook.
A week ago, they released an Android application and sold Facebook for an amount with 9 zeros in dollars. Android owners were happy to:

The developers, however, are not very: “Where are they so drowned? What are they paid for? I can do that too, there is nothing complicated and innovative there! ”Every second Android / iOS developer shouted.
')
Personally, I was waiting for the service to fall on the day the application was released on the Google Play store. But this did not happen. The number of registered users in the first 24 hours was about a million. A good number, I tell you.
And how did the team of 9 people manage to endure such an influx and not break?Here's how
(all the data is reliably taken from the Instagram blog ) :
Measurements: counters and timers
In order to keep track of everything that happens inside, you must somehow monitor all the activity. Usually these are two types of activity: some amounts (counters, registrations per second, for example) and some time intervals (timers, how long it takes to like a vintage photo, for example). But what to do when you have more than one car on the balcony, but a couple of dozen in the DC, and we need one general schedule, and not a couple of dozen different ones? The solution is simple — store everything in a single database. But this operation is not so fast. UDP comes to the exit! Yes, instead of pushing everything into the database, we will simply throw special packets on UDP with data on one common server, and the server will receive them, summarize and represent graphically. So, for this all on Instagram use NodeJS daemon called
"statsd" . He catches all this wealth, and then sends them straight to
Graphite (
graphing thing, as you might have guessed ).
All this is very scalable (in Instagram the polling interval is 10 seconds), so it allows you to monitor everything that happens almost in realtime.
PGFouine is used to monitor PostgreSQL servers. It builds analytics on the basis of PG server logs, allowing you to detect heavy requests and cache them, or non-optimized requests, requests that pull out extra data, etc.
Zombie processes
It's terribly sad when a 500 error is thrown out to the client after a timeout expires, isn't it? And who is to blame? All are silent, and the only witness has already been killed (
kill -9 ). Instagram comes to the aid of Bitbucket with their open-source development for Django called
dogslow . This dog clings to each request at the very beginning, and if after 25 seconds the response to the request has not come, it merges the call tracing somewhere, for example, to the mail.
With it, the guys found out that memcached was a bottleneck, which hung on set () and get_many () requests, generating 50,000 requests per second, without using the whole processor and, as a result, slowing down the whole process.
Replication and slavery
The main backends for data storage on Instagram, Inc. are Redis & PostgreSQL. As you know, both of these engines were thinking about scalability, so they allowed the guys to connect slaves “on the go” as soon as resources started to run out.
In the first 12 hours, the frequency of queries to the Redis database reached 40,000, which began to affect performance. It took no more than 20 minutes to connect additional servers. Impressive, isn't it?
Amazon EBS Snapshots were used to scale Postgre. It also took no more than 20 minutes to connect them, thanks to the easily tuned AWS environment in which their master servers hang out.
Android chips
In addition to all this, the guys wrote a node2dm utility, a node.js server for sending push notifications to the android C2DM service. According to them, he processed about 5 million notifications that day. In honor of this,
node2dm was presented to the community completely open-source.