At JavaOne 2008, LinkedIn employees presented two sessions about the LinkedIn architecture. The slides are available online:
- LinkedIn – A Professional Social Network Built with Java™ Technologies and Agile Practices
- LinkedIn Communication Architecture
These slides are hosted at SlideShare. If you register then you can download them as PDF’s.
This post summarizes the key parts of the LinkedIn architecture. It’s based on the presentations above, and on additional comments made during the presentation at JavaOne.
Site Statistics
- 22 million members
- 4+ million unique visitors/month
- 40 million page views/day
- 2 million searches/day
- 250K invitations sent/day
- 1 million answers posted
- 2 million email messages/day
Software
- Solaris (running on Sun x86 platform and Sparc)
- Tomcat and Jetty as application servers
- Oracle and MySQL as DBs
- No ORM (such as Hibernate); they use straight JDBC
- ActiveMQ for JMS. (It’s partitioned by type of messages. Backed by MySQL.)
- Lucene as a foundation for search
- Spring as glue
Server Architecture
2003-2005
- One monolithic web application
- One database: the Core Database
- The network graph is cached in memory in The Cloud
- Members Search implemented using Lucene. It runs on the same server as The Cloud, because member searches must be filtered according to the searching user’s network, so it’s convenient to have Lucene on the same machine as The Cloud.
- WebApp updates the Core Database directly. The Core Database updates The Cloud.
2006
- Added Replica DB’s, to reduce the load on the Core Database. They contain read-only data. A RepDB server manages updates of the Replica DB’s.
- Moved Search out of The Cloud and into its own server.
- Changed the way updates are handled, by adding the Databus. This is a central component that distributes updates to any component that needs them. This is the new updates flow:
- Changes originate in the WebApp
- The WebApp updates the Core Database
- The Core Database sends updates to the Databus
- The Databus sends the updates to: the Replica DB’s, The Cloud, and Search
2008
- The WebApp doesn’t do everything itself anymore: they split parts of its business logic into Services.
The WebApp still presents the GUI to the user, but now it calls Services to manipulate the Profile, Groups, etc. - Each Service has its own domain-specific database (i.e., vertical partitioning).
- This architecture allows other applications (besides the main WebApp) to access LinkedIn. They’ve added applications for Recruiters, Ads, etc.
The Cloud
- The Cloud is a server that caches the entire LinkedIn network graph in memory.
- Network size: 22M nodes, 120M edges.
- Requires 12 GB RAM.
- There are 40 instances in production
- Rebuilding an instance of The Cloud from disk takes 8 hours.
- The Cloud is updated in real-time using the Databus.
- Persisted to disk on shutdown.
- The cache is implemented in C++, accessed via JNI. They chose C++ instead of Java for two reasons:
- To use as little RAM as possible.
- Garbage Collection pauses were killing them. [LinkedIn said they were using advanced GC's, but GC's have improved since 2003; is this still a problem today?]
- Having to keep everything in RAM is a limitation, but as LinkedIn have pointed out, partitioning graphs is hard.
- [Sun offers servers with up to 2 TB of RAM (Sun SPARC Enterprise M9000 Server), so LinkedIn could support up to 1.1 billion users before they run out of memory. (This calculation is based only on the number of nodes, not edges). Price is another matter: Sun say only "contact us for price", which is ominous considering that the prices they do list go up to $30,000.]
The Cloud caches the entire LinkedIn Network, but each user needs to see the network from his own point of view. It’s computationally expensive to calculate that, so they do it just once when a user session begins, and keep it cached. That takes up to 2 MB of RAM per user. This cached network is not updated during the session. (It is updated if the user himself adds/removes a link, but not if any of the user’s contacts make changes. LinkedIn says users won’t notice this.)
As an aside, they use Ehcache to cache members’ profiles. They cache up to 2 million profiles (out of 22 million members). They tried caching using LFU algorithm (Least Frequently Used), but found that Ehcache would sometimes block for 30 seconds while recalculating LFU, so they switched to LRU (Least Recently Used).
Communication Architecture
Communication Service
The Communication Service is responsible for permanent messages, e.g. InBox messages and emails.
- The entire system is asynchronous and uses JMS heavily
- Clients post messages via JMS
- Messages are then routed via a routing service to the appropriate mailbox or directly for email processing
- Message delivery: either Pull (clients request their messages), or Push (e.g., sending emails)
- They use Spring, with proprietary LinkedIn Spring extensions. Use HTTP-RPC.
Scaling Techniques
- Functional partitioning: sent, received, archived, etc. [a.k.a. vertical partitioning]
- Class partitioning: Member mailboxes, guest mailboxes, corporate mailboxes
- Range partitioning: Member ID range; Email lexicographical range. [a.k.a. horizontal partitioning]
- Everything is asynchronous
Network Updates Service
The Network Updates Service is responsible for short-lived notifications, e.g. status updates from your contacts.
Initial Architecture (up to 2007)
- There are many services that can contain updates.
- Clients make separate requests to each service that can have updates: Questions, Profile Updates, etc.
- It took a long time to gather all the data.
In 2008 they created the Network Updates Service. The implementation went through several iterations:
Iteration 1
- Client makes just one request, to the NetworkUpdateService.
- NetworkUpdateService makes multiple requests to gather the data from all the services. These requests are made in parallel.
- The results are aggregated and returned to the client together.
- Pull-based architecture.
- They rolled out this new system to everyone at LinkedIn, which caused problems while the system was stabilizing. In hindsight, should have tried it out on a small subset of users first.
Iteration 2
- Push-based architecture: whenever events occur in the system, add them to the user’s "mailbox". When a client asks for updates, return the data that’s already waiting in the mailbox.
- Pros: reads are much quicker since the data is already available.
- Cons: might waste effort on moving around update data that will never be read. Requires more storage space.
- There is still post-processing of updates before returning them to the user. E.g.: collapse 10 updates from a user to 1.
- The updates are stored in CLOB’s: 1 CLOB per update-type per user (for a total of 15 CLOB’s per user).
- Incoming updates must be added to the CLOB. Use optimistic locking to avoid lock contention.
- They had set the CLOB size to 8 kb, which was too large and led to a lot of wasted space.
- Design note: instead of CLOB’s, LinkedIn could have created additional tables, one for each type of update. They said that they didn’t do this because of what they would have to do when updates expire: Had they created additional tables then they would have had to delete rows, and that’s very expensive.
- They used JMX to monitor and change the configuration in real-time. This was very helpful.
Iteration 3
- Goal: improve speed by reducing the number of CLOB updates, because CLOB updates are expensive.
- Added an overflow buffer: a VARCHAR(4000) column where data is added initially. When this column is full, dump it to the CLOB. This eliminated 90% of CLOB updates.
- Reduced the size of the updates.
[LinkedIn have had success in moving from a Pull architecture to a Push architecture. However, don't discount Pull architectures. Amazon, for example, use a Pull architecture. In A Conversation with Werner Vogels, Amazon's CTO, he said that when you visit the front page of Amazon they typically call more than 100 services in order to construct the page.]
The presentation ends with some tips about scaling. These are oldies but goodies:
- Can’t use just one database. Use many databases, partitioned horizontally and vertically.
- Because of partitioning, forget about referential integrity or cross-domain JOINs.
- Forget about 100% data integrity.
- At large scale, cost is a problem: hardware, databases, licenses, storage, power.
- Once you’re large, spammers and data-scrapers come a-knocking.
- Cache!
- Use asynchronous flows.
- Reporting and analytics are challenging; consider them up-front when designing the system.
- Expect the system to fail.
- Don’t underestimate your growth trajectory.

June 5th, 2008 at 4:23 am
It is nice to see another big java implementation, not to mention one that uses a lot of good open source tools.
June 5th, 2008 at 11:36 am
[...] gern mal wissen möchte, wie moderne grosse Webseiten laufen, der kann sich hier die LinkedIn-Architecture anschauen und durchlesen. Und wieder ist Lucene die Search-Engine der Wahl. Interessant ist der [...]
June 5th, 2008 at 1:43 pm
Java rules, we’re using same set of tools but lack of good design ….
Well done, LinkedIn team!!!
June 5th, 2008 at 2:12 pm
[...] Arquitectura de LinkedInhurvitz.org/blog/2008/06/linkedin-architecture por jccpUEM hace pocos segundos [...]
June 5th, 2008 at 5:32 pm
[...] LinkedIn Architecture At JavaOne 2008, LinkedIn employees presented two sessions about the LinkedIn architecture. The slides are available online: [...]
June 5th, 2008 at 7:11 pm
[...] I read today where LinkedIN uses ActiveMQ as part of their architecture. I haven’t used ActiveMQ personally, but we use it for a project where I work and the guy [...]
June 5th, 2008 at 10:19 pm
I agree, is nice to look a large scale java application, I will take a look at the papers to see if they can be used as examples to mount similar applications. Thanks…
June 5th, 2008 at 11:46 pm
[...] used memcached and just accepted that data served would be stale, old and wrong. So it was nice to read about LinkedIn’s architecture – where the headlines are: * Mostly Java. Java might be hysterically slow, but in this space it’s [...]
June 6th, 2008 at 12:05 am
[...] găsit AICI un post foarte interesant despre arhitectura LinkedIn. Interesante sunt și [...]
June 6th, 2008 at 12:20 am
Superb info! Thanks.
June 6th, 2008 at 1:36 am
[...] Cookies are for Closers » LinkedIn Architecture (tags: linkedin scalability architecture performance java programming) [...]
June 6th, 2008 at 1:38 am
[...] read more [...]
June 6th, 2008 at 3:32 am
[...] Cookies are for Closers » LinkedIn Architecture (tags: architecture scalability java linkedin performance programming hardware reference code **) [...]
June 6th, 2008 at 4:31 am
[...] entire LinkedIn network graph in memory. # Network size: 22M nodes 120M edges # Requires 12 GB RAMread more | digg [...]
June 6th, 2008 at 6:14 am
Lots of technology. Wish it were used to support a service that actually provided something of value.
June 6th, 2008 at 6:36 am
[...] Cookies are for Closers » LinkedIn Architecture Interesting post describing the architecture of the LinkedIn application. (tags: architecture apps scalability) [...]
June 6th, 2008 at 7:30 am
[...] Cookies are for Closers » LinkedIn Architecture (tags: architecture memori.us Startup scalability) [...]
June 6th, 2008 at 9:19 am
[...] Интересные факты и подробности об архитектуре сервиса LinkedIn, Cookies are for Closers » LinkedIn Architecture [...]
June 6th, 2008 at 9:44 am
[...] are for Closers: LinkedIn Architecture LinkedIn käyttää Javaa Tomcatilla ja Jettyllä, ActiveMQ:ta JMS-liikenteelle, suoria [...]
June 6th, 2008 at 12:47 pm
12 Gbyte should not a problem anymore today, The CMS (concurrent mark and sweep) collector available with the SUN JVM should avoid the pauses almost always.
June 6th, 2008 at 2:46 pm
[...] hurvitz.org) Tags: j2ee, jetty, linkedin, spring, [...]
June 6th, 2008 at 5:00 pm
Unfortunately there is no information about a number of servers used for each service (only one number, that ’40 instances of the graph’). It would be rather interesting to get at least some rough estimates of the cluster size and geographical distribution of the servers (if there is any).
June 6th, 2008 at 6:04 pm
[...] are for Closers (great blog name!) has a post about LinkedIn’s architecture, featuring links to slide decks for two JavaOne 2008 presentations by people from LinkedIn and an [...]
June 6th, 2008 at 6:09 pm
[...] any modern stories of the architectures of popular Web sites today such as the recently published overview of the LinkedIn social networking site’s Web architecture, you will notice a heavy usage of in-memory caching to improve performance. Popular web sites built [...]
June 6th, 2008 at 8:53 pm
[...] For more information on LinkedIn’s implementation, see this excellent article. [...]
June 7th, 2008 at 4:23 pm
However I met some problems on linkedin. For instance, once my user image didn’t show up.
June 7th, 2008 at 7:42 pm
I can attest that Java 5/6 GC can be a real problem once you’ve got more than a few GB of data structures in memory. It took a lot of experimentation to arrive at a mix of configs that worked tolerably. The key was finding the right balance of MaxNewSize and SurvivorRatio to minimize the tenuring of garbage.
June 8th, 2008 at 4:08 pm
Как?!? Неужели кто-то не пользует хибернэйт?
June 17th, 2008 at 7:28 pm
thank you
June 19th, 2008 at 8:28 pm
[...] for Football it is over for us, let us dream that we are designing the right way ). Have a look at their presentations. No Hibernate, Agile methodology and scalability in mind. Great [...]
June 24th, 2008 at 8:40 pm
LinkedIn could look at our Cacheonix. Cacheonix is a Data Grid solution. It allows you to split cached data into multiple JVMs with smaller heap sizes, so you can have a very large cache w/o disadvantage of long GC pauses.
June 30th, 2008 at 9:27 am
Looked at iterations 1 thru 3. Another alternative would be as follows:
- Have an exclusive table for all updates
for each day
- Have a column in that table to indicate
update type(insert/delete/update etc.)
- Use the column to affect insert/update/
delete etc.
- Truncate the table next day
July 8th, 2008 at 10:15 am
[...] to one of those by pointing to an interesting discussion of the linkedin.com architecture on Oren Hurvitz’s “Cookies are for closers” blog [...]
July 8th, 2008 at 5:55 pm
Good (and hard) job
July 9th, 2008 at 8:36 pm
[...] trouverez (en anglais) un article sur blog d’Oren Hurvitz, qui reprend les grandes lignes de la présentation. Pour les slides de la [...]
July 10th, 2008 at 5:35 am
There is a lot to digest in this article from technical perspective if we could only adopt 20% in our design that would be awesome.
Now if we only have other large website giving us their architecture we all could benefit.
August 25th, 2008 at 8:30 pm
Garbage Collection pauses are not a problem if you go with the Azul System Java compute appliance. We’ve seen > 100 GB heaps without a significant GC pause. (Yeah … surprised the heck outta me too). Takes an integrated solution though.
September 11th, 2008 at 4:06 am
[...] о публикации двух презентаций c JavaOne 2008 о LinkedIn и их обобщении от Overn Hurvitz пронеслось по русскоязычным новостным [...]
December 3rd, 2008 at 12:02 pm
How you think when the economic crisis will end? I wish to make statistics of independent opinions!
March 18th, 2009 at 1:45 am
[...] isn’t the only one getting a performance bang from moving data into memory. Both LinkedIn and Digg keep the graph of their network social network in memory. Facebook has northwards of 800 [...]
March 26th, 2009 at 2:55 pm
[...] LinkedIn Architecture [...]
April 11th, 2009 at 3:47 pm
[...] isn’t the only one getting a performance bang from moving data into memory. Both LinkedIn and Digg keep the graph of their network social network in memory. Facebook has northwards of 800 [...]
July 15th, 2009 at 7:15 pm
[...] – e a Google sabe-o melhor que ninguém. Do tal rant fui parar a uma exposição sobre a arquitectura do LinkedIn e, tristeza das tristezas, acabei por perceber que perdi uma belíssima oportunidade de obter os [...]
January 26th, 2010 at 12:56 pm
I think it’s time to introduce a “Community/Social Application Framework” by LinkedIn team.
October 12th, 2010 at 11:16 am
[...] http://hurvitz.org/blog/2008/06/linkedin-architecture Filed under: Uncategorized | Leave a Comment [...]
July 1st, 2011 at 3:28 pm
[...] LinkedIn [...]