QR code for https://ritchie.dev/

ritchie.dev

Tap to close

Distributed Application Programming Language

Ritchie

Always Distributed,
Laptop to Cloud

Unified backend language for the agentic era. Less code. Easy to review. Correct by design.

catalog.riRitchie
Missing! { String item }
@Catalog {}                           // a stateless service
@Catalog.price(String item) -> Decimal | Missing! {
  r::Clock.sleep(50ms)                      // a slow lookup
  [String: Decimal] prices = ["tea": 3.50, "cake": 4.25]
  if has(prices, item) { return prices[item] }
  return Missing! { item: item }
}

main() {
  Decimal tea, scone, cake
  DateTime start = r::Clock.time()
  {
    tea = @Catalog.price("tea")              // sent at 0 ms
    scone = @Catalog.price("scone")          // sent at 0 ms
    cake = @Catalog.price("cake")            // sent at 0 ms
    print(f"total {tea + scone + cake}")     // 50 ms in all
  } handle Missing! => 0.00
  print(f"elapsed time: {r::Clock.time() - start}")
}
Output will appear here.

Ready

  1. Declares an error type, Missing!, that carries the name of the item that was not found. A name that ends in ! is an error type.
  2. Declares a service, @Catalog. A name that starts with @ is a remote service. It has no fields, so it does not keep any state between calls.
  3. Defines the service's method price. A call returns the item's price as a Decimal, or raises Missing! when the catalog has no price for the item. The | list names every error the method can raise.
  4. Suspends this call for 50 ms, to stand in for a slow lookup such as a database query.
  5. Builds a dictionary from item names to prices. Decimal holds exact decimal amounts, so the total adds up to exactly 7.75.
  6. Returns the item's price when the dictionary has an entry for it.
  7. Raises Missing! with the item's name, because the dictionary has no entry for it. Returning an error value raises it to the caller.
  8. The program's entry point.
  9. Declares the three prices in one statement. Decimal is a 128-bit decimal type, so 0.1 + 0.2 is exactly 0.3, and an overflow raises an error instead of wrapping around.
  10. Reads the current time, in UTC with nanosecond precision, so that the last line can report how long the lookups took.
  11. Opens a block whose statements are all protected by the handler on its closing line.
  12. Sends a price request for tea to @Catalog. The call starts here, and the program waits for its result only where the result is first used, so the next line runs at once.
  13. Sends a price request for scone, also at 0 ms. The catalog has no scone, so this call raises Missing!. The handler gives scone the value 0.00, and the block continues with the next line.
  14. Sends a price request for cake, also at 0 ms, because nothing before it has used a result yet. It runs although the scone lookup failed, because the handler resumes the block after the statement that failed.
  15. Adds the three prices and prints total 7.75, which is 3.50 + 0.00 + 4.25. This is the first use of the results, so the program waits here for all three calls. The calls ran at the same time, so the wait is about 50 ms rather than 150 ms.
  16. Handles Missing! for every statement in the block with a fallback value. Unlike exceptions, a block handler resumes execution at the next statement.
  17. Prints the time since start as a Duration. It is about 50 ms because the three lookups ran concurrently.

First-class support for distributed concepts.

Ritchie has built-in archetypes for distributed system components like stateless services, transactional state, queryable state, and streams, each with interaction semantics defined by RITE. Choose the right archetype for each domain type to match the distributed architecture you need.

@T
Status: Done

Services

Stateless, networked application operations.

$T
Status: In progress

Entities

Durable identity and transactional state.

%T
Status: In progress

Projections

Read-only rows over committed state.

T~>
Status: In progress

Streams

Continuous facts and subscriptions.

T!
Status: Done

Errors

Typed, recoverable domain outcomes.