A brief analysis of the system architecture of Twitter

Source: Internet
Author: User

Three-tier architecture (Three-tier architecture)
The architecture of the site, the traditional approach is the three-tier architecture, the so-called "traditional" does not mean "outdated", trendy technology is immature, the traditional path is more robust.
(1) Presentation layer (presentation tier): Apache Web server, the primary task is to parse the HTTP protocol and distribute the request to the logical layer;
(2) Logic tier: Mongrel rails server, using rails ready-made modules to reduce workload;
(3) Data tier: MySQL;

The data layer comes first:
The core of Twitter is (1) users, (2) messages, and (3) user relations;
Around these cores, the schema design of its core data:
(1) User table users
ID, name, pass, status, ...
(2) Message form MSG
MsgId, author_id, MSG, time, ...
(3) User Relationship form relation
ID, Following_ids, followed_ids

Logic Layer :
When a user publishes a message, it executes in turn:
(1) Save message to MSG table;
(2) Check the user relation table, find out its followed_ids;
(3) Obtain the status of the user in the Followed_ids;
(4) Online IDs, push the message into a queue of queues;
(5) Msg in queue, update the homepage of IDs;
There are many ways to use the queue, such as the Apache Mina,twitter team to implement a kestrel.

Presentation Layer :
There are 2 main functions of the presentation layer:
(1) HTTP protocol processing (HTTP processor);
(2) Distribution device (dispatcher);
Of course, access to Twitter is not just a browser, there may be a mobile phone, because there may be other protocols, there may be other processor.

In any case, the architecture framework is clear as follows:

Figure 1: Schema version 1

Cache=cash is cache equals revenue
The use of the cache is critical to the architecture of a large web site, where responsiveness is the most significant factor affecting the user experience, while the most responsive enemies are disk IO.
Twitter engineers believe that the average response time for a good experience should be around 500ms, and the ideal time is 200-300ms.
The use of the cache is a great aspect of the Twitter architecture, with the cache architecture clearly defined as follows:

Figure 2: Version 2 with cache schema

A brief analysis of the system architecture of Twitter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.