NewsCrawler.org

Building Barista: Formal Verification and TLA+

Building Barista: Formal Verification and TLA+
Image: Reddit

This article is the second part of a series about Barista, a system the author built. It collects hundreds of sources, creates a unique prompt for each user, and sends each user one email per day with the best sources for them. The author wants to make sure no user gets the same email twice. The Send stage runs every 5 minutes, so if Barista crashes after the email provider accepts an email but before the send is recorded in Postgres, the retry sends a duplicate.

To prevent this, the author uses Plunk, which accepts an idempotency key[1] built from the user and the day, such as alice-20260520. If Plunk receives the same key again, it replies with a 409 and sends nothing. Plunk costs 10 times more per email than AWS SES, which has no such key, and the author accepted that cost.

The article then introduces formal verification[2] and model checking[3], where a tool visits every reachable state of a system instead of following single test paths. It explains the TLA+[4] language, which describes states and actions, and works through a small example of a cafe with one croissant left. In that example, the model checker TLC finds an order of actions that breaks the rule that the stock never goes below zero.

Read the original read.thecoder.cafeDiscussion

Sources

Published: First seen: Читать по-русски

Open as a page