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

  • U.S. Department of Justice: Two Chinese nationals arrested for allegedly defrauding at least $73 million through cryptocurrency investments

    According to the official website of the United States Department of Justice, a complaint from the central region of California was made public yesterday, accusing two Chinese nationals of playing a major role in a money laundering scheme involving cryptocurrency investment fraud.Daren Li, 41 years old, is a dual citizen of China and St. Kitts and Nevis, and is also a resident of China, Cambodia, and the United Arab Emirates. He was arrested on April 12th at Hartsfield-Jackson Atlanta International Airport and later transferred to the central region of California. Yicheng Zhang, 38 years old, is a Chinese national currently residing in Temple City, California. He was arrested yesterday in Los Angeles. Today, they are accused of leading a money laundering scheme related to an international cryptocurrency investment scam, involving at least $73 million. These arrests were made possible thanks to the assistance of our international and US partners, demonstrating the Department of Justice's commitment to continuing to combat the entire cybercrime ecosystem and prevent fraud in various financial markets.

  • Hong Kong expands digital yuan pilot to allow e-CNY wallets for cross-border payments

    The Hong Kong Monetary Authority and the People's Bank of China have expanded their cross-border digital yuan pilot to allow Hong Kong residents to use e-CNY wallets for cross-boundary payments. The digital yuan is China's central bank digital currency, which has been piloted for several years and is among the most advanced of its kind globally. Users can set up wallets using just a phone number and top them up in real-time through 17 Hong Kong retail banks. The HKMA plans to work with the Digital Currency Institute to explore enhancing interoperability in payments and corporate use cases, such as cross-border trade settlement.

  • WSJ: GPU cloud computing platform CoreWeave raises $7.5 billion to promote artificial intelligence computing

    CoreWeave, an artificial intelligence cloud computing startup supported by Nvidia, has raised $7.5 billion from investors including BNY Mellon, KKR, and BlackRock. This financing is one of the largest private debt financings ever. Just two weeks ago, CoreWeave completed a $1.1 billion equity financing round with a valuation of $19 billion. As of the end of last year, the company had 14 data centers and plans to double that number to 28 by the end of this year.

  • In the past 24 hours, the entire network has liquidated $139 million, and long orders have liquidated $83.5374 million

    According to Coinglass data, there were liquidations totaling $139 million in the past 24 hours, with a total of 56,471 people being liquidated.Of these, long positions were liquidated for $83.5374 million, short positions were liquidated for $55.4391 million, BTC was liquidated for $39.2379 million, ETH was liquidated for $26.5550 million, and SOL was liquidated for $10.2312 million.

  • Türkiye proposes to align crypto legislation with international standards

    Turkey's ruling party submitted a draft encryption bill to parliament on May 16. The bill focuses on licensing and registration of encryption service providers and aligning with international standards.The draft law aims to update existing legislation to comprehensively regulate the emerging cryptocurrency market. The key areas of focus for the bill include consumer protection, platform transparency, and compliance with financial regulations. The proposed legislation aims to regulate cryptocurrency trading platforms and other service providers in the industry, requiring them to obtain a license from the Capital Markets Board of Turkey.

  • Binance assisted Taiwan’s law enforcement agencies in cracking a major virtual asset case involving nearly NT$200 million

    On May 17th, Binance announced that the Financial Crime Compliance department (FCC) of Binance, in collaboration with the Taiwan Department of Justice Investigation Bureau, has successfully cracked a major criminal case involving money laundering of virtual assets, with an involved amount of nearly 200 million New Taiwan dollars. Throughout the entire case, Binance provided support to Taiwan's crime fighters, offering crucial intelligence and assistance, and played a key role in promoting the investigation.

  • $1.2 billion in notional value of BTC options and $930 million in ETH options are set to expire

    Greeks.live data shows that on May 17th, 18,000 BTC options with a put/call ratio of 0.63 and a maximum pain point of $63,000 (nominal value of $1.2 billion) will expire. Additionally, 320,000 ETH options with a put/call ratio of 0.28 and a maximum pain point of $3,000 (nominal value of $930 million) will also expire. Greeks.live states that this week, inspired by the meme stock craze in the US, BTC ETFs have seen significant inflows, causing BTC to surge above $65,000. However, the rest of the crypto market remains weak, with trading volume continuing to decline, and the divergence in the options data of BTC and ETH reflects this. Looking at the structure of bulk trades and market trades, the downward trend in IV for major deadlines has ended and entered a consolidation phase, with limited downside potential at present. BTC longs and shorts are relatively balanced, while the weak ETH price has led to a continuous decline in market confidence, with selling calls becoming the absolute main transaction.

  • Tether CEO: 1 billion USDT will be issued on Tron Network, but it has been authorized but not yet issued

    On May 17th, Tether CEO Paolo Ardoino announced that 1 billion USDT had been issued on the Tron Network early this morning Beijing time, but not yet released. This means that the amount will be used as inventory for the next issuance request and chain exchange.

  • On-chain indexing service Subsquid completes financing of US$17.5 million, with participation from DFG and others

    Subsquid, a chain indexing service, announced the completion of a $6.3 million financing through the CoinList community. As of now, its total financing amount has reached $17.5 million, with participation from DFG, Hypersphere, Zee Prime, Blockchange, and Lattice. It is reported that its native token, SQD, is scheduled to be listed this Friday. The Subsquid SDK has been integrated with Google BigQuery, allowing developers to use Google's technology to analyze blockchain data and reduce the data costs of large-scale deployment in the blockchain and developer communities.

  • Optimism 2024 Q1 Report: The implementation of EIP-4844 reduces L1 submission costs by 99%

    Optimism has released its Q1 2024 report, which shows that the number of daily active addresses has reached 89,000 (a 23% increase compared to the previous period), and the daily transaction volume has increased to 470,000 (a 39% increase compared to the previous period). These indicators are slightly lower than the historical high point in Q3 2023.