## Effortless orchestration with ![Temporal logo](assets/img/temporal-logo.svg) --- # The problem -- Long running, complex interactions... <!-- .element: class="fragment" --> ...in distributed systems... <!-- .element: class="fragment" --> ...with transactional characteristics. <!-- .element: class="fragment" --> -- ## Example <img src="assets/img/interaction.svg" alt="Interaction example" class="stretch"> -- ## Failure <img src="assets/img/interaction-failure.svg" alt="Interaction failure" class="stretch"> -- ## Queues FTW <img src="assets/img/interaction-with-queues.svg" alt="Interaction with queues" class="stretch"> -- ## Status? - **User:** what's going on with my order? - **Seller:** incoming orders? - **Developer:** debug a single execution? <img src="assets/img/interaction-with-queues-status.svg" alt="Interaction with queues status" class="stretch"> -- ## Cancellation? - **User:** I changed my mind, give me my money back! - **Payment failed:** User failed to pay the order, cancel it! <img src="assets/img/interaction-with-queues-cancellation.svg" alt="Interaction with queues cancellation" class="stretch"> -- ## State! <img src="assets/img/interaction-state.svg" alt="Interaction state" class="stretch"> -- ## Reinventing wheels <img src="assets/img/reinventing-wheels.png" alt="Reinventing wheels" class="stretch"> *Source: [StackOverflow Blog](https://stackoverflow.blog/2020/11/23/the-macro-problem-with-microservices/)* <!-- .element style="font-size: 13px" --> <!-- .element style="margin-top: -30px;" --> -- ## Lessons learnt - No *one size fits all* solution (yet) - Fragile systems - Lack of orchestration -- ## Lack of orchestration - Fractured business processes - Tight coupling between components - Cancellations? - Compensating actions? - Additional interactions? - Troubleshooting? --- # Temporal -- ## What is Temporal? - Temporal service - Temporal SDK *(insert your programming language here)* -- ## Orchestration as code - Write business logic as plain code - Orchestration framework - Durability and reliability out-of-the-box -- ## Concepts - Workflow - Activity - Worker _[Documentation](https://docs.temporal.io/concepts)_ -- ## Workflow - Encapsulates business logic - Required to be **deterministic** - Implemented in and executed by the _Worker_ _[Documentation](https://docs.temporal.io/workflows)_ -- ## Determinism > Output is based entirely on the input. ```go func add(a, b int) int { return a + b } ``` ```go func add(a, b int) int { // This is not deterministic resp := http.Get(fmt.Sprintf("https://add.com/%d/%d", a, b)) return decodeBody(resp.Body) } ``` -- ## Activity - Building blocks for _Workflows_ - Asynchronously executed - Generally **idempotent** - Runs to completion or exhausts timeouts/retries _[Documentation](https://docs.temporal.io/activities)_ -- ## Idempotence > Applying an operation multiple times does not change the result beyond the initial application. -- ## Example ```go // workflow type: "placeOrder" func placeOrder(o Order) { for _, item := range o.Items { err := temporal.ExecuteActivity("warehouse.ReserveItem", item) // handle error } // ... } // activity type: "warehouse.ReserveItem" func reserveItem(item OrderItem) error { if !items.IsAvailable(item.Quantity) { return ErrItemNotAvailable } // .. return nil } ``` -- ## Worker - Implemented and operated by the user - Executes _Workflows_ and _Activities_ - Listens to _Task Queues_ _[Documentation](https://docs.temporal.io/workers)_ -- <!-- .slide: data-visibility="hidden" --> <img src="assets/img/worker-queues.svg" alt="Worker queues" class="stretch"> -- <img src="assets/img/temporal-high-level.svg" alt="Temporal highlevel" class="stretch"> --- # Further reading -- https://github.com/sagikazarmark/temporal-intro-workshop -- https://stackoverflow.blog/2020/11/23/the-macro-problem-with-microservices/ -- [Documentation: Concepts](https://docs.temporal.io/concepts) [Documentation: Glossary](https://docs.temporal.io/glossary) -- [Documentation: Developer's guide](https://docs.temporal.io/application-development/) -- [Temporal learning materials](https://learn.temporal.io/) --- # The End