Restate Examples

repository·main·Indexed 41 days ago

https://github.com/restatedev/examples

A collection of examples and templates for using Restate to solve common application challenges. Includes Go implementations of core concepts like Durable Execution, Virtual Objects, and Workflows, as well as integration guides for AWS Lambda (CDK), Knative, and Kubernetes via Helm. Features advanced patterns such as event enrichment with Kafka, durable webhook processing, synchronous-to-asynchronous task conversion, and custom cron job implementations using durable timers.

Tokens
96K
Snippets
272
Records
374
Agent score
48%

What's inside Restate

  1. Overview of the Kotlin Multiplatform Todo App Example

    main

    This project is a Kotlin Multiplatform (KMP) example demonstrating a Todo application that uses Restate as its backend. It showcases how to integrate a mobile frontend with Restate services.

    The project is composed of three main parts:

    1. Shared Code: The logic shared across platforms (located in ./shared).
    2. Todos Virtual Object: A Restate service built using the Kotlin Restate SDK to manage todo storage (located in ./server/src/main/kotlin/dev/restate/examples/noteapp/Application.kt).
    3. Android App: The mobile client implementation (located in ./composeApp).
  2. Overview of Python Patterns and Use Cases

    main

    This repository contains various implementation patterns using Restate in Python. These patterns cover several categories of distributed systems challenges:

    Communication

    • Durable RPC, Idempotency & Concurrency: Ensuring requests are processed exactly-once and managing sequential execution for Virtual Objects.
    • (Delayed) Message Queue: Using Restate as a queue to schedule tasks for immediate or future execution.
    • Convert Sync Tasks to Async: Transforming long-running synchronous tasks into asynchronous workflows (e.g., via email notifications).

    Orchestration Patterns

    • Sagas: Managing distributed consistency by tracking and executing undo actions upon failure.
    • Stateful Actors and State Machines: Building state machines using Restate Virtual Objects for automatic state persistence.
    • Payment State Machines: Advanced tracking of payment processes, including cancellations and consistent processing.

    Scheduling

    • Scheduling Tasks: Using Restate as a durable scheduler for future tasks.
    • Parallelizing Work: Executing multiple tasks in parallel and aggregating results.
    • Payment Signals: Handling asynchronous callbacks for slow payment processes (e.g., Stripe).

    Event Processing

    • Transactional Event Processing: Processing events (e.g., from Kafka) to update downstream systems transactionally.
    • Event Enrichment / Joins: Connecting stateful actors to Kafka for data enrichment via RPC.
  3. Explore Restate Use Cases and Patterns in Python

    main

    The Python examples include several implementation patterns for common distributed systems problems:

    Communication

    • Durable RPC, Idempotency and Concurrency: Ensuring requests execute exactly-once by persisting them.
    • (Delayed) Message Queue: Using Restate as a queue to schedule tasks for now or later.
    • Convert Sync Tasks to Async: Turning long-running synchronous tasks (like data uploads) into asynchronous ones.

    Orchestration patterns

    • Sagas: Preserving consistency by tracking undo actions and running them upon failure.
    • Stateful Actors and State Machines: Building state machines using Restate Virtual Objects for automatic state persistence.
    • Payment State Machines (Advanced): Tracking complex payment processes to ensure consistent processing and cancellations.

    Scheduling

    • Scheduling Tasks: Using Restate as a scheduler to trigger and execute tasks at a later time.
    • Parallelizing Work: Executing a list of tasks in parallel and gathering results.
    • Payment Signals (Advanced): Handling asynchronous payment callbacks (e.g., with Stripe).

    Event processing

    • Transactional Event Processing: Processing events (e.g., from Kafka) to update downstream systems transactionally.
    • Event Enrichment / Joins: Connecting stateful functions/actors to Kafka and making them callable over RPC.
  4. Core concepts of Restate in Go

    main

    The Go basics examples demonstrate four primary building blocks of the Restate platform:

    • Durable Execution: Ensures code runs to completion despite failures. It provides automatic retries and recovery of previously finished actions (e.g., ensuring a recurring payment is created before adding a subscription).
    • Building Blocks: Durable versions of standard primitives including queues, promises, RPC, state, and timers.
    • Virtual Objects: Stateful serverless objects used to manage durable, consistent state and the logic required to manipulate that state.
    • Workflows: Durable execution tasks that possess a unique identity. They can be submitted, awaited, signaled, and queried via durable promises (e.g., a multi-step user signup flow).

    Detailed API references and implementation patterns for these concepts can be found in the individual source files: part0/durableexecution.go, part1/buildingblocks.go, part2/virtualobjects.go, and part3/workflows.go.

  5. Browse Restate Basics examples

    main

    The Basics catalog covers fundamental Restate concepts. Examples are available in TypeScript, Go, Python, Java, Kotlin, and Rust for the following topics:

    • Services - Durable Execution: Understanding how services maintain state and progress.
    • Durable Building Blocks: Using core primitives to build reliable systems.
    • Virtual Objects: Managing stateful entities.
    • Workflows: Orchestrating long-running processes.
  6. Browse Restate End-to-End Applications

    main

    View complete, real-world application implementations:

    • Food Ordering App: TypeScript, Python, Java, Kotlin.
    • Image Workflow Parser & Executor: TypeScript, Java.
    • LLM-powered Chat Bot / Task Agent: TypeScript, Python.
    • Subway Fare Calculator: Java.
    • RAG Ingestion: Python.
    • Kotlin Todo App: Kotlin.
    • AI: agentic workflows, MCP, A2A...: See the AI examples repo.
  7. Browse Restate Use Cases and Patterns

    main

    The Use Cases and Patterns catalog provides implementation recipes for common distributed systems challenges. Supported languages include TypeScript, Go, Python, Java, and Kotlin. Key patterns include:

    • Durable RPC, Idempotency & Concurrency
    • (Delayed) Message Queue
    • Webhook Callbacks
    • Sagas
    • Cron Jobs
    • Database Interaction Patterns
    • Convert Sync Tasks to Async
    • Batching
    • Payments Signals (Advanced)
    • Stateful Actors and State Machines
    • Payment State Machines (Advanced)
    • Scheduling Tasks
    • Concurrent async tasks
    • Parallelizing Work
    • Transactional Event Processing
    • Event Enrichment / Joins
    • Durable Promises as a Service
    • Priority Queue
    • Rate Limiting
    • AI: agents, LLM calls, MCP, A2A... (See the AI examples repo for specialized AI patterns)
  8. Explore Restate example catalogs

    main

    The restatedev/examples repository provides several categories of examples to help you learn and implement Restate in your applications:

    • Basics: Small examples demonstrating core building blocks like durable execution and virtual objects.
    • Use Cases and Patterns: Specific implementations for common challenges such as webhooks, workflows, and asynchronous task queuing.
    • Integrations: Demonstrations of how to connect Restate with other popular tools, technologies, and libraries.
    • End-to-End Applications: Full, runnable demo applications (e.g., food ordering or e-commerce sites) typically provided as a docker compose setup.
    • Templates: 'Hello World!' project templates for various languages, build systems, and runtimes, designed to provide a production-ready starting point for services or Lambdas.
    • Tutorials: Step-by-step guides that build applications while introducing Restate concepts incrementally.
  9. Browse Restate Integrations

    main

    Learn how to integrate Restate with existing infrastructure and frameworks:

    • AWS Lambda + CDK: Deployment examples for TypeScript, Go, Java, and Kotlin.
    • XState: Integration with XState (TypeScript).
    • Knative: Integration with Knative (Go).
  10. Core concepts of Restate in Rust

    main

    Restate provides several core abstractions for building resilient applications in Rust:

    • Durable Execution: Ensures code runs to completion despite failures by providing automatic retries and recovery of previously finished actions.
    • Durable Promises: Used to manage asynchronous tasks that can be signaled and queried.
    • Virtual Objects: Stateful serverless objects used to manage durable, consistent state and the logic that manipulates that state.
    • Workflows: Durable execution tasks with a unique identity that can be submitted, awaited, signaled, and queried via durable promises.
  11. Core Restate primitives in Python

    main

    The Python basics examples cover the following core Restate abstractions:

    • Durable Execution: Ensures code runs to completion by automatically retrying and recovering previously finished actions in the event of failures.
    • Durable Promises: Used to interact with Workflows, allowing them to be signaled and queried.
    • Virtual Objects: Stateful serverless objects that manage durable, consistent state and the logic required to manipulate that state.
    • Workflows: High-level durable execution tasks that possess a unique identity and can be managed via durable promises.
    • Building Blocks: A suite of durable primitives including Queues, Promises, RPC, State, and Timers.
  12. Core Restate abstractions in Java

    main

    The Restate Java examples demonstrate four primary building blocks for building durable applications:

    • Durable Execution: Ensures code runs to completion despite failures. It provides automatic retries and recovery of previously finished actions (e.g., ensuring a recurring payment is created before adding a subscription).
    • Building Blocks: Provides durable versions of standard primitives including queues, promises, RPC, state, and timers.
    • Virtual Objects: Stateful serverless objects used to manage durable, consistent state and the logic required to manipulate that state.
    • Workflows: Durable execution tasks that possess a unique identity. They can be submitted, awaited, signaled, and queried via durable promises (e.g., a multi-step user signup flow).