Pinterest Architecture Update - 18M Visitors, 10x Growth, 12 Employees, 410 TB
highscalability.com
highscalability.com
-Python + heavily-modified Django at the application layer
-Tornado and (very selectively) node.js as web-servers.
-Memcached and membase/redis for object and logical-caching
-RabbitMQ as a message queue.
-Nginx, HAproxy and Varnish for static-delivery and load-balancing.
-Persistent data storage using MySQL.
-MrJob on EMR for map-reduce.
[1] http://www.quora.com/Pinterest/What-technologies-were-used-t...
I think by now most startups, YC or not, in Silicon Valley will pretty much have a similar setup:
1) Choose the main web-stack (Rails or Django)
2) Choose the API framework (node.js, or something else)
3) Memcached for caching (or some NoSQL)
4) A message queue (ZeroMQ, RabbitMQ, or something ...)
5) nginx, HAProxy, Varnish, (or similar technology)
6) Hadoop for map-reduce (only if you need to go that path...)
And while this is truly unimportant, my experience with bay area startup stacks is that Redis has very thoroughly supplanted Memcached for most use cases. Though most still have a memcached cluster or two.
That being said: 90% of software development in this world isn't done at tech companies and startups. So from that perspective, that stack is interesting.
(Not that I care about starting the holy war of X vs Y, just out of curiosity why)
You have a point regarding your last statement. Perhaps I've been here far too long to notice more of the 10% and less on the 90% :)
... which is true ... last I read someone is making almost $1M revenue developing Windows desktop app in 2012 and another company is making $60k/monthly revenue developing BB apps using in-apps Ads. I think I'm going to sign-off on HN and go to the other side... :D :D :D
Redis offers persistence, set operations, namespacing, you can delete multiple entries with wildcards...
You can't mix and match (you can theoretically)
Let's say you began with Django, right? Or there was something already ready in Django.
And then you begin to see the warts. But ok, you keep churning along.
And the more you churn the more of a specialist in the deficiencies of each technology you become. Like the fact that Django's ORM runs like a dog.
Or see all the "we moved to MongoDB and we regret it" discussions
From that list, there are two technologies I would recommend strongly (if you know what you are doing): nginx and Redis
The rest needs to be handled with care. And Redis is very powerful if you know how to use, but it's easy to go the "lazy way" with it, and it will be fast, but not as fast as it can.
... as in: check the output of SQL queries constructed by Django ORM and tweaked it in your Django Model layer such that the resulted SQL query will be tuned for performance?
Or at the very least, shouldn't Django ORM at least provide a way to retrieve data with "filtering" as optional parameters? (get only a few columns, but not all..)
If you're reading "just tables" without, or with simple relations and conditions, it's ok (because, as you pointed out, that's basically SELECT with)
The problem is when for example you have inheritance, or moderately complex relations.
Then you'll see Django spamming your DB with requests and the DB may be fast but the operation will be slow because of the sheer number of requests.
So yeah, in a sense you can optimize for it, or use SqlAlchemy (which is good, but it has a different philosophy than the Django ORM in the way it's used)
My experience is heavily in Java (JPA2 and Hibernate) and less of Rails (simple/moderate apps). Typically an ORM provides a way to handle custom queries but still help maps the result to the Java object model (which helps a lot vs writing getter/setter :)).
I don't know how people down south in Silicon Valley design their model (especially young scrappy startup) but I have a slightest doubt that they go that far (advanced/complex). It's not like startup start with "analyzing requirements" and move on to "modelling session" :) => they just go ahead and write code.
So in theory, the data model shouldn't be complex enough to warrant edge-case.
Use the tools to launch faster, then optimize.
Though I've had to work around some of Rails defaults for my use cases, there is no doubt that without it we'd not have been able to launch and iterate so quickly.
There isn't anything very revolutionary about their stack by itself. FB didn't buy them for their technology... they could have replicated that on their own.
If they want to be talking about infrastructure, the story of using common tools at high volume is more interesting that just what tools...
However, is it not reasonable that would someone not consider node.js, as web stack as well?
I will agree the focus is more towards backend and asynchronous API's traditionally, but the amount of front-end/UX orientated modules are growing every day.
Not a big fan of node.js (or JavaScript for that matter) and probably never will so I can't comment much.
-Instagram[0]
-Disqus
Disqus.com - Disqus serves over 3 billion page views, and more than 500 million unique visitors a month on it's Django stack. As far as we know we are the largest installation out there.
-Mozilla[2]
addons.mozilla.com and support.mozilla.com
250k+ add-ons, 150 million views per month, 500+ million api hits per day (firefox checking for updates!
-Justin.tv(they moved to Django from Rails)[3]
-NASA
-National Geographic
-Canonical
-Bitbucket.org
-Discovery Networks
-Intel, AMD, HP, IBM
-Lexis-Nexis
-The Library of Congress
-The New York Times
-Orbitz
-PBS
-Rdio: Huge traffic Radio site.
-VMWare
-Walt Disney
-The Washington Post.
-lanyrd.com
-OSQA Sites. OSQA is an Open Sourced similar copy of Stackoverflow, a QnA community. AFAIK some 5K sites are powered by OSQA Stack. OSQA is built on Django.
-Youtube, LinkedIN, Google, NetFlix, Amazon: Python Stacks.
-GMail, Google Calendar, AdSense, AdWords, Android MarketPlace to name a few of the heavy hitters from Google are on Python - Google App Engine.
[0]http://techcrunch.com/2012/04/12/how-to-scale-a-1-billion-st...
[1]http://jacobian.org/writing/django-community/django-communit...
[2]http://reinout.vanrees.org/weblog/2011/06/06/large-mozilla-s...
References-
[3] http://stackoverflow.com/questions/886221/does-django-scale
[4] http://www.quora.com/Django/What-is-the-highest-traffic-webs...
Why the downvotes? Parent post is just pointing out sites which he/she knows to be using Python and/or Django, some of which are incorrect(Gmail?), or are giving the impression that they run on Python when only small sub-projects are using it(LinkedIn?, Amazon?). There are some mistakes, but on a whole, I don't see anything wrong with someone pointing out something relevant to the discussion, even if it involves bragging about something he is associated with.
I would double check your sources on that one.
Just commenting ... :D
Likewise with Amazon. My understanding, from chatting with some Amazon engineers at a conference, is that they have a pretty heterogeneous portfolio, even including some Perl and Oracle PL/SQL.
Others who are better informed, please correct.
Seibel: As a Java guy at Google, do you think it could be used more? Leaving aside the force of history and historical choices, if somehow you could wave a magic wand and replace all of C++ with Java, could that work?
Bloch: Up to a point. Large parts of the system could be written that way, and over time, things are moving in that direction. But for the absolute core of the system - the inner loops of the index servers, for instance - very small gains in performance are worth an awful lot. When you have that many machines running the same piece of code, if you can make it even a few percent faster, then you've done something that has real benefits, financially and enviromentally. So there is some code that you want to write in assembly language, and what is C but glorified assembly language?
http://google-opensource.blogspot.ca/2009/01/opengse-release...
(I think Google Sites is also written in Java).
Amazon is pretty much a big Java shop (don't forget the companies they acquired as well). Check out their jobs site.
On top off edwinnathaniel's list, add Google Sites, Google Docs, and Mapreduce frameworks such as Flume Java.
Sure it is. But I won't use Java for web stuff. I might use it for some background services, but for regular CRUD functionality, Java buys me nothing. I generally use Python(Flask)/Jinja2/Flask-SqlAlchemy. Flask is intuitive; Jinja2 is pleasant and fast; Flask-SQLAlchemy is concise with the option of exploring the raw power of SQLAlchemy. For regular use cases, nothing in Java beats this combination. I have looked at Play; it comes closer but it's still not there.
Checkout this toy benchmark that was doing the rounds 2 months ago https://github.com/grahamking/Key-Value-Polyglot The naive python solution https://github.com/grahamking/Key-Value-Polyglot/blob/master... performs dog slow. Java has real threads, JIT; but guess what, the naive Java solution still is dog slow https://github.com/grahamking/Key-Value-Polyglot/blob/master...
My specialized python solutions are magnitudes of times faster than both naive Python and Java solutions:
https://github.com/rahulkmr/Key-Value-Polyglot/blob/master/m... https://github.com/rahulkmr/Key-Value-Polyglot/blob/master/m...
The naive solutions were taking around 20 seconds to do 500 writes followed by 500 reads. My changed solution does 5000 writes followed by 5000 reads in under 2 seconds. The 500 and 5000 aren't typos - the naive solutions was taking about 20 seconds for 1000 operations, whereas tailored solution was doing 10000 operations under 2 seconds.
This is the discussion thread http://news.ycombinator.com/item?id=3733090
I get it that this is an IO bound problem, and naturally an epoll based solution will totally smoke a thread-per-request solution, but that's the point I am trying to make. If at the end of the day, intuitive solutions don't work and I have to do custom implementations, I am not getting much out of using Java. I might use it for something which is CPU bound about 70% of the time, but anything other than that, the pains far outweigh benefits.
Better keep up with the latest frameworks and libraries.
I know Rails and Django and I used cherrypy, cheetah, and sqlalchemy as well, and Java is on par with both modern frameworks if you know to choose the right frameworks.
In fact, I do not have to deploy multiple processes one for Rails and one for sinatra or node.js. Just some app server or web container and I am ready to go.
... And you are asking me to check out a "toy benchmark"?
I care more for the overall solutions from deployment, tools, etc. End to end baby...
What are these frameworks in Java you talk about which are as expressive as Django and Rails? Less verbose that it was before isn't the same as as expressive as Rails/Django.
> In fact, I do not have to deploy multiple processes one for Rails and one for sinatra or node.js. Just some app server or web container and I am ready to go.
Rails/Django deployment isn't that hard. If you are talking about a large app, deployment is a very small consideration compared to other aspects.
As far as multiple processes go, more often than not, large apps are run as collection of co-operating services. That is by choice, irrespective of whether it's implemented in Java or Python. Which one of the examples you listed you think runs as some app server and container?
> ... And you are asking me to check out a "toy benchmark"? > I care more for the overall solutions from deployment, tools, etc. End to end baby...
All benchmarks are toys. If you want "end to end", the only way is to do it is to implement the same app in Python and Java, and then compare them. Doing that would be batshit insane(sure, we are going to do too versions of pinterest to compare whether we write it in Java or Python), nobody does that, nobody should do that.
As far as benchmark goes, I only claimed that out of box code in Java performs like dogshit, and I am to jump hoops, I would rather jump hoops in Python, Ruby, Clojure et al.
Spring MVC is on par with Rails VC (let's leave ActiveRecord for another time) or Django TV minus Django ORM.
Testing? Spring has a really good testing library that plays with both straight up Java EE components (Servlet, Portlet, etc). Functional, Integration, Unit-Test, name your game.
Migration? Flyway works nicely and I don't have to spend days to set it up, just less than an hour for multi-year project. Minuscule in terms of effort. It just works.
I'll give you that ActiveRecord is nicer than JPA 2 (but not by a lot). The rest are... indifferent, same stuff, same type, same ol' same ol'.
JAX-RS can spits both XML and JSON easily with no code changes. I don't have to use Sinatra (or node.js) for web-api and deploy it separately from Rails: just deploy JAX-RS project as a separate WAR to the AppServer and I'm done. Done.
I don't need to spin up a different process, write a script to do X,Y,Z, maintain another infrastructure, etc etc.
Regarding your mark about benchmark: then don't start flashing numbers and stuffs if they are toys. If OOB Java is like dog stuff then Python, Ruby are like snail or turtle.
Wait, what am I doing trolling like redditors or slashdotters over mindless debate.
sigh technology has never been the problem, the people are sigh always holds true.
For me, expressiveness is the sum of language expressiveness, framework, culture and api design.
For example, see this crime against humanity
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<c:choose>
<c:when test="${emails.unread != null && fn:size(emails.unread)}">
You have ${fn:size(emails.unread)} unread email(s)!
</c:when>
<c:otherwise>
You have no unread emails!
</c:otherwise>
</c:choose>
Now, the designers could have very well implemented: You have ${emails.unread ?: 'no'} ${emails.unread?.pluralize('email')} !
> I think you have a different mindset on that one but I'm not sure what you're trying to achieve.I am not trying to achieve anything, and it's not just a matter of mindset. See my example above. Expressiveness isn't just something which is confined to the language. Horrendous apis and frameworks are a bane for any language.
> Migration? Flyway works nicely and I don't have to spend days to set it up, just less than an hour for multi-year project.
I don't follow your remark that you don't have to spend days to set it up. Which migration lib takes days to set up? I am not contesting there isn't something bad out there(see my JSP example above), but since we are talking Rails/Django, I don't see how it is relevant here.
> JAX-RS can spits both XML and JSON easily with no code changes. I don't have to use Sinatra (or node.js) for web-api and deploy it separately from Rails:
Umm what? Rails needs Sinatra to produce JSON?
def foo
respond_to do |format|
format.html { }
format.json { }
format.xml { }
end
end
> Wait, what am I doing trolling like redditors or slashdotters over mindless debate.
> sigh technology has never been the problem, the people are sigh always holds true.I won't bother responding to this.
A typical setup is to use Rails for front-facing website and Sinatra for web-services (RESTful).
What I'm saying is that that can be done with Spring MVC + JAX-RS:
@Produces("application/xml")
@Produces("application/json")
// Want more? add your own? very flexible
// @Produces("application/atom")
// @Produces("text/plain")
// @Produces("application/something+xml") <-- custom
public Employee get(@Parameter("id") final int id){
// code no need to pepper with respond_to
}You said frameworks don't decide expressiveness. I was quoting an example that they do. Whether you use jsp or not is tangential. Java isn't anywhere near python or ruby in terms of expressiveness, neither are the frameworks.
EDIT: Like another commenter pointed out, if you can get a 55k LSoC Java project down to 8k Python project, that says something about expressiveness.
FYI, you can mount your sinatra app in your rails app and run them in the same process.
Nothing against Java, it's the best tool for the job on many occasions but launching quickly and scaling fast are not it's forté.
I find Java to be much more modular and adaptable to different web paradigm: old school MVC, one page JS style (GWT or pure JS), asynchronous (Netty or Servlet 3.0), scalable web api that can spit both xml and json without extra coding (JAX-RS), component oriented (JSF).
The integration between business logic and let say if you somehow need to use message queue are quite good via EJB 3.1 (very minimum coding) and JMS.
Java took a beating a few years ago, fast forward to 2012, they have improved quite significantly. In the next two years, multi tenant architecture will be available in JavaEE 7 out of the box.
Many people who keep complaining about Java typically are those who have wayy past experience.
Last year, we switched a 55k loc Spring MVC (with JAX-RS for the json api) over to Django (using tastypie for the api side and celery for offline tasks). The result ended up being little over 8k loc of Python. Closing a ticket has gone from taking on average around 5 days to a little over 4 hours. That was the third project we ported over, the others having had similar success. YMMV.
Why Django not Rails since Rails seem to be more popular?
I found it hard to believe that you can switch 55k LoC of Spring MVC + JAX-RS to Django with resulted of 8k. Because from what I've learned over the year, the amount of code requires to write Spring MVC + JAX-RS is very minimum and very close to Rails (my experience is more with Rails) at the very least from the Controller point of view. My personal like of the paradigm is to re-use the code between Spring MVC and JAX-RS. Love it so much.
That is of course if you discount everything else: imports, comments, parentheses, configurations. What about the actual logic?
We typically use JS heavy on the front end and less on JSF/JSP.
But you're right, YMMV. Projects have different requirements and skillset/experience. We typically don't have technical bugs but more of requirement bugs: someone forgot to handle the case of X,Y,Z and as such, it requires about a day or less to plug the issues.
I hadn't started when the decision to go Django instead of Rails was made (Rails & .NET MVC were also considered) but I've been told it came down to a number of things:
* This is in Europe, generally Ruby is not used very much over here, Python has been used in some shape or form in every company I've have experience of but I've only seen Ruby recently and then mostly for Chef or Puppet.
* Lack of explicit imports did not work in Ruby's favour.
* If needed numpy & scipy don't have a analogue in the Ruby ecosystem.
* General negativity towards the religious zeal permeating through the Rails community.
ASP.NET MVC won't have much gain over Spring MVC/JAX-RS. In fact, there's nothing similar to JAX-RS in ASP.NET MVC (you'd have to write your own stuff here and there and wire them together, not as straightforward as JAX-RS).
This is an excellent story to share both from technical perspective (Java+Frameworks => Django+Python+Pythonic mindset) and from recruiting perspective. I hope one day you could share (perhaps in slides/presentation style) the actual code and technique in details.
Mind if I ask you where in Europe? (Country/City?) For a while I thought Europe is Rails heavy.
While comparing loc, take into account the fact that there were no unknowns - you are simply porting functionality. You generally don't have to solve a problem when you are re-writing a Java codebase in Python, just pythonizing the existing java solution. I would wager if the same system was re-written in Java, it would shave some bloat(provided you are re-implementing and not adding features).
With that said, 55k to 8k is still very impressive.
I mean really we're all just moving 1's and 0's around.
Yes, but Rails is another huge factor too (the ORM, Ruby itself, etc.)—you would get Rails scaled somehow to 18m visitor but it's damn hard.
The link above is the modified, famous "blog in 10 minutes". When I was starting, I found it very pleasant as it covers the 20% of the Rails which you use 80% of the time.
For reference, that's about four times bigger than the iTunes music catalog (20mio MP3 files * 5MB average filesize = 100TB).
(even though this is probably around scalability and connecting with other technologies)
Scalability and uptime is still hard
Still, Pinterest is laying on a great infrastructure (EC2, Elastic Map Reduce) and using it to the fullest.
Nice, compared to the usual, "The database was at 100% capacity, then we tried to shard/partition, and it did not go too well."
Data: $52/h (peak time, let's say 18 out of 24 hours) and $15/h (night time, let's say 6/24).
Edit: as pointed in the comments $30k/month would only be the EC2 costs.
It is also interesting that they seem to be using Akamai for a CDN instead of Cloudfront so not a completely AWS based solution.
I wish they went into what they are storing in S3. 410TB is a lot of storage. My initial guess was cached images but 80M objects breaks down to 5MB per object and that is a lot more than what is needed for image caching.
Looks like a switch to dedicated hardware would amortize within... 3 months.
Yes, they obviously have quite a few loose screws (read: whoever invested 100MM in that).
Either way, this is not a matter of "tightening". It's a matter of hiring an admin and having him not only pay for himself after 3 months, but for 1-2 other employees, too.
Yes, when you have 100MM in the bank then a mundane couple dozen thousand dollars a month might seem to matter less. But I can't think of a company where that kind of decadence has led to anything positive in the mid term.
No wonder 37signals decided to switch to their self-hosted storage solution[1].
Visio almost hit $1B according to insider... (can't verify).