Skip to main content
Kafka event processing requires managing Kafka consumers, handling retries, maintaining state stores, and coordinating complex workflows. Restate eliminates this complexity by providing lightweight, transactional event processing with zero consumer management and built-in state.

Workflows from Kafka

Build event handlers with complex control flow, loops, timers, and transactional guarantees:
export default restate.object({
  name: "userFeed",
  handlers: {
    processPost: async (ctx: restate.ObjectContext, post: SocialMediaPost) => {
      const userId = ctx.key;

      // Durable side effect: persisted and replayed on retries
      const postId = await ctx.run(() => createPost(userId, post));

      // Wait for processing to complete with durable timers
      while ((await ctx.run(() => getPostStatus(postId))) === PENDING) {
        await ctx.sleep({ seconds: 5 });
      }

      await ctx.run(() => updateUserFeed(userId, postId));
    },
  },
});
Key Benefits:
  • Push-based delivery: Events delivered directly to handlers with zero consumer management
  • Durable execution: Failed handlers are retried with exponential backoff until they succeed. Handlers replay previously completed steps and resume exactly where they left off.
  • Parallel processing: Events for different keys process concurrently, like a queue per object key
  • Timers and scheduling: Timers and delays that survive crashes and restarts for long-running workflows

Stateful Event Handlers

Maintain K/V state across events:
export default restate.object({
  name: "delivery-tracker",
  handlers: {
    register: async (ctx: restate.ObjectContext, delivery: Delivery) =>
      ctx.set("delivery", delivery),

    setLocation: async (ctx: restate.ObjectContext, location: Location) => {
      const delivery = await ctx.get<Delivery>("delivery");
      if (!delivery) {
        throw new TerminalError(`Delivery not found`);
      }

      delivery.locations.push(location);
      ctx.set("delivery", delivery);
    },

    getDelivery: shared(async (ctx: restate.ObjectSharedContext) =>
      ctx.get<Delivery>("delivery")
    ),
  },
});
Key Benefits:
  • Persistent state: Store and retrieve state directly in handlers without external stores
  • Built-in consistency: State operations are always consistent with execution
  • Agents, actors, digital twins: Model stateful entities that react to events

When to Choose Restate

✅ Choose Restate when you need:
  • Kafka integration: Process Kafka events with zero consumer management
  • Reliable processing: Automatic retry and recovery for failed event handlers
  • Transactional processing: Execute side effects with durable execution guarantees
  • Stateful event processing: Maintain state across events without external stores
  • Event-driven workflows: Build complex flows with loops, timers, and conditions
Processing events with Restate? Join our community on Discord or Slack to discuss your use case.

Comparison with Other Solutions

FeatureRestateTraditional Kafka ProcessingStream Processing Frameworks
Event DeliveryPush-based to durable handlersPolling-based consumer groupsBuilt-in sources and sinks
Consumer ManagementZero configurationManual offset and consumer group managementZero configuration
Failure RecoveryFine-grained progress persistence with durable side effectsCoarse-grained offset commits with potential reprocessingCoarse-grained checkpointing with potential duplicate side effects
State ManagementBuilt-in durable stateExternal state store requiredBuilt-in state store
Queuing SemanticsQueue-per-key with ordering guaranteesQueue-per-partition with ordering guaranteesQueue-per-partition (inherited from Kafka)
Complex WorkflowsUnlimited control flow: loops, timers, conditionsLong-running logic blocks consumer loop; requires external servicesDAG-based processing with limited control flow
Best ForEvent-driven state machines, transactional processing, complex workflowsSimple ETL and message processingHigh-throughput analytics, aggregations, joins

Getting Started

Ready to build event processing systems with Restate? Here are your next steps:
Evaluating Restate and missing a feature? Contact us on Discord or Slack.
I