Cointime

Download App
iOS & Android

The Goldilocks consensus problem

Imagine that you wanted to build a sufficiently decentralized Twitter — a social network in which no single person or company is in control. How would you build something like that?

A social network is decentralized if it has many servers run by different people. The data would be spread across servers, so you’d need a simple way to answer questions like “What are the latest posts?”. This is where consensus comes in.

We developed a new consensus model for Farcaster, our decentralized social network. Existing models had user experience and decentralization tradeoffs, making scaling a social network difficult. Our model, called a deltagraph, uses blockchains and CRDTs to scale to millions, and hopefully billions, of users.

Why do we need a new consensus model?

Federation and blockchains, which are common models in untrusted networks, have tradeoffs that aren’t ideal for a social network. Federation is simple but leads to centralization, while blockchains prevent this but are slow and expensive.

In a federated system, anyone can run a server. Users pick the one they like, and all servers are loosely connected. In practice, federated services become oligopolies. Email is an example of this, where it’s very difficult to start a new server as a new developer. There are many unwritten rules and gatekeepers that you have to get past.

Without a forcing function, servers in a federated system diverge over time. APIs and data formats become slightly different, intentionally or due to bugs. Developers write workarounds that become implicitly enshrined, making the system more complex and opaque. Federated servers start out simple because there isn’t formal consensus, but this tradeoff creates systemic complexity.

Blockchains have a consensus model to prevent exactly this kind of problem. Unfortunately, the type of consensus they use makes them too slow and expensive for social networks. Twitter users generate over 100,000 updates a second 1, while a modern blockchain is 100x slower under ideal conditions 2. Users must pay for each post they add to the blockchain. It is hard to grow a social network under these constraints.

Would faster blockchains solve this? The tradeoffs that blockchains make to support financial transactions make this unlikely. Consensus must prevent double spending, which limits the strategies that can be used. People invent new ways to financialize things on blockchains which creates demand. The appetite for financial transactions seems insatiable even as supply increases, making it hard to store social data at a reasonable cost.

Social networks face a Goldilocks problem — federated consensus is too weak, and blockchain consensus is too strong.

Solving the Goldilocks problem with CRDTs

Blockchains reach consensus by letting one node decide the transaction order. Other nodes must send transactions to them and wait for a confirmation. This step is slow because it requires coordination over a network, but it is essential to prevent double-spending.

A social network network doesn’t need perfect ordering. Little harm is done if Alice’s posts show up in your feed before Bob’s. Farcaster’s consensus model - the deltagraph - uses CRDTs, which can reach consensus without coordination but do not guarantee a global order.

A deltagraph is made up of deltas, which are the atomic units of change. Deltas are stored on nodes, servers that accept them from users and forward them to other nodes. Alice can say “Hello World” by creating an add-post delta and sending it to a node. She can delete it later by sending a remove-post delta. When a node gets the remove, it will discard the add-post and store the remove-post instead.

What happens if deltas arrive in a different order? A “remove-wins” rule handles this case. The rule says that if a post is removed, it can never be added again. With these rules enforced, you can send deltas as many times as you like and in any order, and they end up in the same state. This is very different from blockchains, where reordering transactions changes outcomes.

The deltagraph organizes deltas into sets and graphs. A set maps to something a user can do, like posting a message. It will store deltas related to that action and enforce rules. The rules are always commutative, associative, and idempotent, and they behave like anonymous delta-state CRDTs 3. A graph is a collection of sets that belong to a user.

Deltas across graphs can be merged without rules because they can’t affect each other. Even if Alice says “Hello world” and Bob replies, the deltas can be processed in any order. Deltagraph consensus is quick because it can run in parallel and without network calls.

Once a node achieves local consensus, it broadcasts deltas to other nodes. Syncing is more complex than blockchains because there is no global order. Two nodes have to compare all their sets to find missing deltas. There’s ongoing research to improve sync speed in deltagraphs.

Deltagraphs are much faster at consensus, but we still have a problem. What happens if someone broadcasts a billion deltas? Nodes would sync this with each other, run out of storage, and the entire network would crash.

Charging rent

Farcaster solves the overload problem by charging rent to store deltas. Users pay a storage fee and can post as many deltas as they like for a year. Nodes store a certain number of deltas for each user, and if the limit is crossed, the oldest deltas are removed.

In a feed-based social network, older messages expiring will have little impact on today’s feed, and users can rent more storage to keep a longer history around.

Deltagraphs apply a ‘last-write-wins’ which means that older deltas expire when the set is full. This rule can be stacked on top of the existing set rules while allowing deltas to be merged in any order. For instance, if Alice has three deltas with increasing timestamps - A1, A2, A3 - and the set can only store two deltas, the two most recent deltas will remain after the set logic runs.

The problem with charging rent is that the deltagraph can’t move money. This is a good thing because it reduces demand for space. We don’t want Alice, who is trying to post a photo of her cat, to compete with Bob, who is trying to day trade. But how do we collect rent?

Farcaster’s deltagraph relies on a blockchain to handle the ordered transactions 4. A user must first make an onchain transaction to create an account and pay rent from their wallet. They can then create a delta, sign it with their wallet, and send it to the deltagraph. The deltagraph tracks onchain events and verifies the delta’s signature before accepting it.

The deltagraph doesn’t have to worry about byzantine fault problems. Thanks to CRDTs, most actions don’t need coordinated consensus, and the few that do are outsourced to a blockchain. It’s only concern is handling p2p layer challenges like denial-of-service and eclipse attacks5.

What’s next for deltagraphs?

The deltagraph isn’t theoretical — Farcaster has been using it for a year and has over 300,000 paying users. The network has 1,000 nodes serving 5 million deltas every day. Our goal is to reach Twitter scale while staying decentralized and providing a great user experience, and we see a clear path ahead.

Deltagraphs augment blockchains, enabling applications that weren’t cost-effective before. This design pattern might unlock other use cases that we haven’t yet considered. Alternate approaches to consensus — CRDTs, verifiable compute, or something else entirely — could be paired with blockchains to decentralize games, marketplaces, and other consumer apps.

Thanks to Shilpa LokareddyDan RomeroGeorgios KonstantopoulosSanjay RaveendranCassie Heart and Polynya for help with drafts.

  1. Twitter data is hard to come by these days. The last known number was 6,000 tweets per second. After adding reactions, follows and accounting for growth, the number is likely ~100,000. 
  2. Decentralized blockchains range from 60 (Ethereum) to 1600 (Solana) today. Source
  3. van der Linde, A., Leitão, J., & Preguiça, N. (2016). Δ-CRDTs: Making δ-CRDTs delta-based
  4. Farcaster’s contracts live on OP Mainnet, but any programmable blockchain would work. 
  5. Heilman, E., Kendler, A., Zohar, A., & Goldberg, S. (2015). Eclipse attacks on bitcoin’s peer-to-peer network
Comments

All Comments

Recommended for you

  • FSDC recommends four growth paths to promote Hong Kong as a digital asset hub

    Hong Kong Monetary Authority's Chief Executive, Eddie Yue, attended the annual meeting of the Hong Kong Independent Non-Executive Directors Association and pointed out that Hong Kong can develop from four growth paths: asset and wealth management center, international sustainable finance center, promoting Hong Kong as a digital asset center, international innovation and technology center.

  • Ethereum's market value exceeds Mastercard and LVMH, and its global asset market value ranking rises to 26th

    According to Infinite Market Cap data, the current market value of Ethereum has reached 443 billion US dollars, surpassing the market value of companies such as Mastercard and LVMH, ranking 26th in the world's asset market value ranking.

  • Crypto and blockchain venture capital firm New Form Capital launches $100 million fundraising

    New Form Capital, a venture capital firm in the cryptocurrency and blockchain industry, has launched a $100 million fundraising campaign aimed at returning to the once troubled cryptocurrency industry. New Form Capital stated that the focus of the investment will be on reshaping traditional finance with cryptocurrency-related technologies, including trading markets and payment systems. In addition, they revealed that they will also invest in some artificial intelligence startups related to cryptocurrency and blockchain.

  • Hong Kong Ethereum ETF has shown net redemption or zero net flow for 9 consecutive trading days. This morning, it showed a positive premium for a short period of time and the trading volume was

    According to SoSo Value data, the net flow of Hong Kong Ethereum spot ETF was zero on May 20, with a total holding of 1332 Ethereum and a daily turnover of 243,000 US dollars. The total net assets were 41.14 million US dollars. From May 7 to the present, the net flow of Hong Kong Ethereum ETF has been zero or net redemption for 9 trading days.In terms of asset size, Bosera Hashkey ETF holds 6300 Ethereum, ranking first, while Huaxia and Jiashi ETF hold 4640 and 2390 Ethereum respectively. In terms of intraday discount rate, Bosera HashKey ETF and Jiashi ETF had a positive premium rate this morning, and the trading volume has also increased. As of the time of publication, the total intraday trading volume has exceeded 1.489 million US dollars, and Huaxia Ethereum ETF has reached 883,000 US dollars, exceeding the full-day trading volume of yesterday.(Note: ETF net flow of zero is normal, indicating a balance between buying and selling quantities. Bloomberg ETF analyst James Seyffart pointed out that among approximately 3,500 US ETFs, 2,903 had a net flow of zero on a certain day.)

  • 62 crypto projects raised $474 million so far in May

    According to the latest data, in the past 20 days of May, 62 blockchain or cryptocurrency projects raised a total of $474 million. The blockchain project Sophon, which focuses on entertainment, raised $60 million in node sales, followed closely by Securitize with a funding amount of $47 million. (Bitcoin.com)

  • The open interest of Ethereum futures contracts across the network is nearly $14.7 billion, a record high

    On May 21st, Coinglass data showed that the total open position of Ethereum futures contracts on the network rose to 4.01 million ETH (approximately $14.69 billion), an increase of 25.48% in the past 24 hours, reaching a historic high when calculated in USD (there is still a gap from the peak of 5 million ETH in 2022). Among them, Binance's open position for Ethereum contracts was 1.5 million ETH (approximately $5.48 billion), ranking first; the increase in holdings in the past 24 hours was 32.37%. Bybit's open position for Ethereum contracts was 840,490 ETH (approximately $3.08 billion), ranking second, with an increase in holdings of 38.82% in the past 24 hours.

  • Yuga Labs co-founder: The company will no longer touch Cryptopunks, it will be completely decentralized

    On May 21st, Garga.eth, co-founder of Yuga Labs, announced on X platform that Yuga Labs will no longer be involved with Cryptopunks. Cryptopunks will be fully decentralized and stored on the blockchain. When the company acquired Cryptopunks and other collectibles a few years ago, the intention was to preserve them as heritage. Yuga Labs only intends to support some museums and institutions in obtaining Cryptopunks. In addition, the current plan is to randomly airdrop Nina's latest NFT collection to Super Cool World holders.

  • The U.S. SEC responds to Ripple’s sealed motion: objecting to some evidence in certain documents related to the application for remedial measures

    On May 21st, according to legal documents shared by former US federal prosecutor James K. Filan, the US Securities and Exchange Commission (SEC) has submitted a response to Ripple's sealed motion. The SEC stated its opposition to certain evidence in some of the documents submitted by Ripple related to its application for remedies.

  • Chairman of the Hong Kong Institute of International Finance: Using Hong Kong's digital financial infrastructure to explore the RMB-pegged "Greater Bay Area Stablecoin"

    Professor Xiao Geng, Chairman of the Hong Kong International Finance Association, Professor of the Advanced Finance Research Institute of the Chinese University of Hong Kong (Shenzhen), and Director of the Policy and Practice Research Institute, stated that Hong Kong has always been a testing ground for cutting-edge financial innovation, with a good tradition of innovation, a good system for implementing experiments, and a good market foundation. Creating a stablecoin linked to the renminbi based on stablecoins, limited memory blockchains, and digital smart contracts can consolidate and enhance Hong Kong's status as an international financial center.

  • The Hong Kong Insurance Authority is considering changing its name to “virtual insurance”, which may be consistent with the logic of changing the name of virtual banks

    According to Li Jiada, CEO of Hong Kong virtual bank WeLab Bank, the Hong Kong Insurance Authority is considering renaming "virtual insurance". If virtual banks and virtual insurance are renamed with the same logic, it is believed that further synergies can be achieved. Li Jiada said that "digital" can more accurately highlight the core characteristics of providing digital financial services through technology, clearly defining the service model and characteristics of such banks. "Licensed" highlights regulatory compliance, helps strengthen customer confidence in local virtual banks, and is beneficial for virtual banks to attract new customers and continue to develop.