Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Durable Functions 2.0

Durable Functions 2.0

Andrea Ceroni

October 17, 2019
Tweet

More Decks by Andrea Ceroni

Other Decks in Programming

Transcript

  1. NEXT CONFERENCES CODEMOTION MADRID: September, 24-25 CODEMOTION MILAN: October, 24-25

    CODEMOTION BERLIN: November, 12-13 CODEMOTION ROME 2020: March, 27-28 CODEMOTION AMSTERDAM 2020: May, 27-28
  2. Durable Functions stateful patterns Function chaining F1 F2 F3 Async

    HTTP APIs Start DoWork GetStatus Long-running monitor Event aggregator Human interaction RequestApproval ProcessApproval Escalate Fan-out / fan-in F1 F2 F3
  3. Durable Functions Actions [DurableClient] IDurableOrchestrationClient Client Function • Start orchestration

    • Query orchestration • Terminate orchestration • Signal orchestration • Signal entity • Query entity [OrchestrationTrigger] IDurableOrchestrationContext Orchestrator Function • Call an activity • Call sub-orchestrator • Set status • Call entity [EntityTrigger] IDurableEntityContext Entity Function • Initialize • Destroy • Handle event • Set state • Get state
  4. Durable Entities Serverless virtual actors very similar to actors (Akka.Net,

    Orleans...) but with some substantial differences Explicit state express the state " in an explicit way " and not in the form of a workflow as happens with orchestrators, but they can be used together with orchestrators Reliability for messages (call and signal) "exactly-once" delivery is guaranteed communication takes place through persistent queues (Azure Storage Queue) which guarantee sorting and de-duplication Messages are processed one at a time
  5. EntityId EntityId an entity is uniquely defined by its id

    in the form @EntityType@EntityKey, for example @Light@Hue1 SingnalEntityAsync vs CallEntitiyAsync "signaling" means the enqueue of an operation (asynchronous command, ane-way) "call" instead is usable only inside an orchestrator and returns an answer directly Proxy defining an interface, which the entity will implement, we can perform operations on the entity in a type-safe way avoiding the " magic strings " in code
  6. Comparison with virtual actors Commons: • addressable via ID •

    serial execution of operations • automatically created during the first opeartion • unloaded from memory when not in use • messages are delivered in order and reliably • support for distributed lock via orchestrator • pattern request / response possible only from the orchestrator (entity-to-entity signaling only, as in the actors) Differences:
  7. public class Question { public string Answer { get; set;

    } public void AskAQuestion(string question) => Answer = ThinkAboutTheAnswer( J ); public string GetAnswer() => this.Answer; [FunctionName(nameof(Question))] public static Task Run( [EntityTrigger] IDurableEntityContext ctx, => ctx.DisptachAsync<Question>(); }