diff --git a/typescript/patterns-use-cases/README.md b/typescript/patterns-use-cases/README.md index f44e29fa..cb84730e 100644 --- a/typescript/patterns-use-cases/README.md +++ b/typescript/patterns-use-cases/README.md @@ -2,22 +2,34 @@ Common tasks and patterns implemented with Restate: -| Use case / Pattern | | | Difficulty | Description | -|--------------------------------------------------------|---------------------------------------------------------|--------------------------------------------------------------------------------------------------------|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Durable RPC, Idempotency and Concurrency | [code](src/durablerpc/express_app.ts) | [README](README.md#durable-rpc-idempotency-and-concurrency) | Basic | Use the programmatic clients to invoke Restate handlers. Add idempotency keys for deduplication. And limit concurrency via Virtual Objects. | -| (Delayed) Message Queue | [code](src/queue/task_submitter.ts) | [README](README.md#delayed-message-queue) | Basic | Use Restate as a queue. Send a (delayed) event to a handler. Optionally, retrieve the response later. | -| Sagas | [code](src/sagas/booking_workflow.ts) | [README](README.md#sagas) | Basic | Preserve consistency by tracking undo actions and running them when code fails halfway through. Restate guarantees completion. | -| Webhook Event Processing | [code](src/webhookcallbacks/webhook_callback_router.ts) | [README](#durable-webhook-event-processing) | Basic | Point webhook callbacks to a Restate handler for durable event processing. | -| Scheduling Tasks | [code](src/schedulingtasks/payment_reminders.ts) | [README](#scheduling-tasks-and-durable-webhooks) | Basic | Use Restate as scheduler. Schedule tasks for later and ensure the task is triggered and executed. | -| Stateful Actors and Durable State Machines | [code](src/statefulactors/machine_operator.ts) | [README](README.md#stateful-actors-and-durable-state-machines) | Basic | Stateful Actor representing a machine in our factory. The handlers bring the machine up and down and track the state transitions, built as a Restate Virtual Object for automatic state persistence. | -| Event processing: Transactional handlers | [code](src/eventtransactions/user_feed.ts) | [README](README.md#event-processing-transactional-handlers-with-durable-side-effects-and-timers) | Basic | Processing events (from Kafka) to update various downstream systems in a transactional way. With durable side effects and timers. | -| Event processing: Enriching streams | [code](src/eventenrichment/package_tracker.ts) | [README](README.md#event-processing-event-enrichment) | Basic | Stateful functions/actors connected to Kafka and callable over RPC. | -| Parallelizing work | [code](src/parallelizework/fan_out_worker.ts) | [README](README.md#parallelizing-work) | Intermediate | Execute a list of tasks in parallel and then gather their result. | -| Turn slow sync tasks into async | [code](src/dataupload/client.ts) | [README](README.md#async-data-upload) | Intermediate | Kick of a synchronous task (e.g. data upload) and turn it into an asynchronous one if it takes too long. | -| Payment state machines | [code](src/statemachinepayments/payment_service.ts) | [README](README.md#payment-state-machine) | Advanced | State machine example that tracks a payment process, ensuring consistent processing and cancellations. | -| Payments: combining sync responses and async callbacks | [code](src/signalspayments/payment_service.ts) | [README](README.md#payment-signals---combining-sync-responses-and-async-webhook-callbacks-from-stripe) | Advanced | Handling async payment callbacks for slow payments, with Stripe. | -| Patterns: Durable Promises | [code](durablepromise) | [README](README.md#pattern-durable-promises) | Advanced | Custom implementation of Promises/Futures that are durable across processes and failures. | -| Patterns: Priority Queue | [code](priorityqueue) | [README](README.md#pattern-priority-queue) | Advanced | Example of implementing a priority queue to manage task execution order. | +**Basics:** + +| Use case / Pattern | Code | README | Description | +|------------------------------------------|--------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Durable RPC, Idempotency and Concurrency | [code](src/durablerpc/express_app.ts) | [README](README.md#durable-rpc-idempotency-and-concurrency) | Use the programmatic clients to call Restate handlers. Add idempotency keys for deduplication. | +| (Delayed) Message Queue | [code](src/queue/task_submitter.ts) | [README](README.md#delayed-message-queue) | Use Restate as a queue. Send a (delayed) event to a handler. Optionally, retrieve the response later. | +| Sagas | [code](src/sagas/booking_workflow.ts) | [README](README.md#sagas) | Preserve consistency by tracking undo actions and running them when code fails halfway through. Restate guarantees completion. | +| Webhook Event Processing | [code](src/webhookcallbacks/webhook_callback_router.ts) | [README](#durable-webhook-event-processing) | Point webhook callbacks to a Restate handler for durable event processing. | +| Scheduling Tasks | [code](src/schedulingtasks/payment_reminders.ts) | [README](#scheduling-tasks-and-durable-webhooks) | Use Restate as scheduler. Schedule tasks for later and ensure the task is triggered and executed. | +| Stateful Actors and State Machines | [code](src/statefulactors/machine_operator.ts) | [README](README.md#stateful-actors-and-durable-state-machines) | Stateful Actor representing a machine in our factory. The handlers bring the machine up and down and track the state transitions, built as a Restate Virtual Object for automatic state persistence. | +| Event processing: Transactional handlers | [code](src/eventtransactions/user_feed.ts) | [README](README.md#event-processing-transactional-handlers-with-durable-side-effects-and-timers) | Processing events (from Kafka) to update various downstream systems in a transactional way. With durable side effects and timers. | +| Event processing: Enriching streams | [code](src/eventenrichment/package_tracker.ts) | [README](README.md#event-processing-event-enrichment) | Stateful functions/actors connected to Kafka and callable over RPC. | + +**Intermediate:** + +| Use case / Pattern | | | Description | +|--------------------------------------------------------|---------------------------------------------------------|--------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Parallelizing work | [code](src/parallelizework/fan_out_worker.ts) | [README](README.md#parallelizing-work) | Execute a list of tasks in parallel and then gather their result. | +| Turn slow sync tasks into async | [code](src/dataupload/client.ts) | [README](README.md#async-data-upload) | Kick of a synchronous task (e.g. data upload) and turn it into an asynchronous one if it takes too long. | + +**Advanced:** + +| Use case / Pattern | | | Description | +|--------------------------------------------------------|---------------------------------------------------------|--------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Payment state machines | [code](src/statemachinepayments/payment_service.ts) | [README](README.md#payment-state-machine) | State machine example that tracks a payment process, ensuring consistent processing and cancellations. | +| Payments: combining sync responses and async callbacks | [code](src/signalspayments/payment_service.ts) | [README](README.md#payment-signals---combining-sync-responses-and-async-webhook-callbacks-from-stripe) | Handling async payment callbacks for slow payments, with Stripe. | +| Patterns: Durable Promises | [code](durablepromise) | [README](README.md#pattern-durable-promises) | Custom implementation of Promises/Futures that are durable across processes and failures. | +| Patterns: Priority Queue | [code](priorityqueue) | [README](README.md#pattern-priority-queue) | Example of implementing a priority queue to manage task execution order. | First, install the dependencies: