An engineer who created a Mastodon instance that can handle access on the same scale as X (old Twitter) with 1/100 the amount of code appeared



By implementing

Mastodon , a decentralized SNS, using a platform called ' Rama ', we succeeded in realizing an instance that can handle the same scale of access as X (formerly Twitter) with 1/100 the amount of code of X. said the developer of Rama in a blog post.

How we reduced the cost of building Twitter at Twitter-scale by 100x – Blog
https://blog.redplanetlabs.com/2023/08/15/how-we-reduced-the-cost-of-building-twitter-at-twitter-scale-by-100x/


Rama is a general-purpose platform for building application backends, and can build end-to-end backends of any scale with 1/100th of the code. Rama's developers are said to have decided to implement Mastodon instances in Rama to demonstrate that ``the amount of code is really 1/100''.

The Mastodon instance created this time is hosted at ' https://mastodon.redplanetlabs.com/ '. 100 million bots are running to show that it can withstand the load, and the average number of posts per second is about 3500 posts. Each post reaches an average of 403 followers, with some posts reaching as many as 22 million followers. According to the blog, 7000 tweets per second are delivered to an average of 700 followers on X, so this Mastodon instance can be scaled up to the same scale as X if the server cost is increased. Is possible. In addition, since this instance was prepared only for demonstration purposes, it is scheduled to be closed after a certain amount of operation.

The implementation of this instance is shown below. Mastodon's backend is written as a Rama module, and this part handles data processing, indexing, etc. In addition, it implements Mastodon API with Spring and Reactor , and uses Soapbox for the front end. AWS's S3 will be used to serve images and movies. The total amount of code is 10,000 lines, and the Rama module and API server are implemented with about 5000 lines each.



An important feature of this implementation is that the processing capacity increases in proportion to the increase in the number of nodes, as shown in the figure below. Every time a post is made, it needs to be written on the timelines of users who follow the user who posted it, and the average number of times that post is written is shown in the figure below as a metric called 'average fan-out.' On X, 7000 tweets are posted per second with an average fanout of about 700, but if we recalculate this with an average fanout of 403 in our test environment, the load is equivalent to posting 12,200 tweets per second. Masu. In our tests, we handled nearly 20,000 posts per second, proving that we can scale beyond X without any problems.



The figure below shows the distribution of time from posting to being displayed on the follower's timeline. When an account with a large number of followers posts, the load increases sharply, which tends to cause delays in the development of other posts. Compared to

X's latency of 1.8 seconds at the 99th percentile, it can be said that the processing is quite fast.



Also, the distribution of the time it takes to acquire the user's home timeline data is as shown in the figure below. In order to build a home timeline, in addition to the data of posts that are not muted or filtered, it is necessary to use statistical data such as the number of replies and favorites, and information about the account that posted, such as the user name, display name, and profile image. Therefore, the fact that the home timeline data is retrieved in an average of 87ms proves that the backend is efficient.



The implementation code and Rama of Mastodon this time are still private at the time of article creation, and will be released gradually in the future. By August 22, 2023, a demo and documentation that can simulate a Rama cluster will appear, and by August 29, 2023, it is said that the Mastodon implementation code will be open sourced.

The specific code itself has not been released yet, but the original blog explains in great detail how Rama's ideas and how they were used to build the Mastodon instance. If you are interested, please check it out.

in Software,   Web Service, Posted by log1d_ts