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

Help! I've created a serverless monolith! - CloudBrew

Marc Duiker
November 18, 2022

Help! I've created a serverless monolith! - CloudBrew

Slides for my CloudBrew 2022 session.
I talked about serverless monoliths, how unmaintainable apps cause problems with agility and how to measure agility. How accidental complexity can be reduced or moved, and I offered three strategies how to breakup a serverless monolith based on, bounded context, resilience, and scalability.

Marc Duiker

November 18, 2022
Tweet

More Decks by Marc Duiker

Other Decks in Programming

Transcript

  1. @MarcDuiker 2
    Marc Duiker
    Sr Developer Advocate

    View full-size slide

  2. @MarcDuiker 3

    View full-size slide

  3. @MarcDuiker 5

    View full-size slide

  4. @MarcDuiker 6

    View full-size slide

  5. @MarcDuiker 7

    View full-size slide

  6. @MarcDuiker 8

    View full-size slide

  7. @MarcDuiker 9
    https://en.wikipedia.org/wiki/Monolithic_application
    “In software engineering, a monolithic
    application describes a software application
    that is designed without modularity.”

    View full-size slide

  8. @MarcDuiker 10
    https://en.wikipedia.org/wiki/Modularity
    “…modularity is the degree to which a
    system's components may be separated and
    recombined, often with the benefit of
    flexibility and variety in use.”

    View full-size slide

  9. @MarcDuiker 11
    App Server DB Server

    View full-size slide

  10. @MarcDuiker 12
    Function App
    Function App Queue Storage

    View full-size slide

  11. @MarcDuiker 13
    Function App
    Function App Queue Storage

    View full-size slide

  12. @MarcDuiker 14

    View full-size slide

  13. @MarcDuiker 15

    View full-size slide

  14. @MarcDuiker 16

    View full-size slide

  15. @MarcDuiker 18
    https://martinfowler.com/articles/agileStory.html
    “We eventually agreed on "agile" as we felt
    that captured the adaptiveness and
    response to change which we felt was so
    important to our approach…”

    View full-size slide

  16. @MarcDuiker 19

    View full-size slide

  17. @MarcDuiker 20

    View full-size slide

  18. @MarcDuiker 21

    View full-size slide

  19. @MarcDuiker 22

    View full-size slide

  20. @MarcDuiker 24

    View full-size slide

  21. @MarcDuiker 25
    Task on backlog Work started Work completed

    View full-size slide

  22. @MarcDuiker 26
    https://www.atlassian.com/incident-management/kpis/common-metrics

    View full-size slide

  23. @MarcDuiker 27
    https://www.atlassian.com/incident-management/kpis/common-metrics

    View full-size slide

  24. @MarcDuiker 28
    https://www.atlassian.com/incident-management/kpis/common-metrics

    View full-size slide

  25. @MarcDuiker 29

    View full-size slide

  26. @MarcDuiker 30

    View full-size slide

  27. @MarcDuiker 31
    https://learn.microsoft.com/en-us/azure/azure-functions/functions-host-json

    View full-size slide

  28. @MarcDuiker 32

    View full-size slide

  29. @MarcDuiker 33
    https://learn.microsoft.com/en-us/azure/azure-functions/functions-deployment-slots

    View full-size slide

  30. @MarcDuiker 34
    Function App
    Website Queue

    View full-size slide

  31. @MarcDuiker 35

    View full-size slide

  32. @MarcDuiker 37
    Caused by the nature of the
    (business) problem.
    Can’t be easily reduced.
    Caused by decisions we make related
    to architecture, frameworks,
    packages, code style etc.
    Can be reduced.
    https://en.wikipedia.org/wiki/Programming_complexity

    View full-size slide

  33. @MarcDuiker 38
    https://en.wikipedia.org/wiki/Programming_complexity
    Caused by decisions we make related
    to architecture, frameworks,
    packages, code style etc.
    Can be reduced.
    Caused by the nature of the
    (business) problem.
    Can’t be easily reduced.

    View full-size slide

  34. @MarcDuiker 39

    View full-size slide

  35. @MarcDuiker 40

    View full-size slide

  36. @MarcDuiker 41

    View full-size slide

  37. @MarcDuiker 42

    View full-size slide

  38. @MarcDuiker 43

    View full-size slide

  39. @MarcDuiker 44

    View full-size slide

  40. @MarcDuiker 45

    View full-size slide

  41. @MarcDuiker 46

    View full-size slide

  42. @MarcDuiker 47

    View full-size slide

  43. @MarcDuiker 48

    View full-size slide

  44. @MarcDuiker 49
    public static class ChainingExample
    {
    [FunctionName(nameof(ChainingExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var resultA = await context.CallActivityAsync(
    nameof(ActivityFunctionA),
    null);
    var resultB = await context.CallActivityAsync(
    nameof(ActivityFunctionB),
    resultA);
    var resultC = await context.CallActivityAsync(
    nameof(ActivityFunctionC),
    resultB);
    return resultC;
    }
    }

    View full-size slide

  45. @MarcDuiker 50
    public static class ChainingExample
    {
    [FunctionName(nameof(ChainingExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var resultA = await context.CallActivityAsync(
    nameof(ActivityFunctionA),
    null);
    var resultB = await context.CallActivityAsync(
    nameof(ActivityFunctionB),
    resultA);
    var resultC = await context.CallActivityAsync(
    nameof(ActivityFunctionC),
    resultB);
    return resultC;
    }
    }

    View full-size slide

  46. @MarcDuiker 51
    public static class ChainingExample
    {
    [FunctionName(nameof(ChainingExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var resultA = await context.CallActivityAsync(
    nameof(ActivityFunctionA),
    null);
    var resultB = await context.CallActivityAsync(
    nameof(ActivityFunctionB),
    resultA);
    var resultC = await context.CallActivityAsync(
    nameof(ActivityFunctionC),
    resultB);
    return resultC;
    }
    }

    View full-size slide

  47. @MarcDuiker 52
    public static class ChainingExample
    {
    [FunctionName(nameof(ChainingExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var resultA = await context.CallActivityAsync(
    nameof(ActivityFunctionA),
    null);
    var resultB = await context.CallActivityAsync(
    nameof(ActivityFunctionB),
    resultA);
    var resultC = await context.CallActivityAsync(
    nameof(ActivityFunctionC),
    resultB);
    return resultC;
    }
    }

    View full-size slide

  48. @MarcDuiker 53
    public static class ChainingExample
    {
    [FunctionName(nameof(ChainingExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var resultA = await context.CallActivityAsync(
    nameof(ActivityFunctionA),
    null);
    var resultB = await context.CallActivityAsync(
    nameof(ActivityFunctionB),
    resultA);
    var resultC = await context.CallActivityAsync(
    nameof(ActivityFunctionC),
    resultB);
    return resultC;
    }
    }

    View full-size slide

  49. @MarcDuiker 54

    View full-size slide

  50. @MarcDuiker 55
    public static class FanOutFanInExample
    {
    [FunctionName(nameof(FanOutFanInExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var tasks = new List>();
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionA),
    null));
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionB),
    null));
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionC),
    null));
    var results = await Task.WhenAll(tasks);
    return results;
    }

    View full-size slide

  51. @MarcDuiker 56
    public static class FanOutFanInExample
    {
    [FunctionName(nameof(FanOutFanInExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var tasks = new List>();
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionA),
    null));
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionB),
    null));
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionC),
    null));
    var results = await Task.WhenAll(tasks);
    return results;
    }

    View full-size slide

  52. @MarcDuiker 57
    public static class FanOutFanInExample
    {
    [FunctionName(nameof(FanOutFanInExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var tasks = new List>();
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionA),
    null));
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionB),
    null));
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionC),
    null));
    var results = await Task.WhenAll(tasks);
    return results;
    }

    View full-size slide

  53. @MarcDuiker 58
    public static class FanOutFanInExample
    {
    [FunctionName(nameof(FanOutFanInExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var tasks = new List>();
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionA),
    null));
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionB),
    null));
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionC),
    null));
    var results = await Task.WhenAll(tasks);
    return results;
    }

    View full-size slide

  54. @MarcDuiker 59
    public static class FanOutFanInExample
    {
    [FunctionName(nameof(FanOutFanInExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var tasks = new List>();
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionA),
    null));
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionB),
    null));
    tasks.Add(context.CallActivityAsync(
    nameof(ActivityFunctionC),
    null));
    var results = await Task.WhenAll(tasks);
    return results;
    }

    View full-size slide

  55. @MarcDuiker 60

    View full-size slide

  56. @MarcDuiker 61
    public static class SubOrchestratorExample
    {
    [FunctionName(nameof(SubOrchestratorExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var resultA = await context.CallSubOrchestratorAsync(
    nameof(SubOrchestratorA),
    null);
    var resultB = await context.CallSubOrchestratorAsync(
    nameof(SubOrchestratorB),
    resultA);
    var resultC = await context.CallSubOrchestratorAsync(
    nameof(SubOrchestratorC),
    resultC);
    return resultC;
    }
    }

    View full-size slide

  57. @MarcDuiker 62
    https://github.com/marcduiker/durable-functions-use-cases

    View full-size slide

  58. @MarcDuiker 64

    View full-size slide

  59. @MarcDuiker 66
    Domain
    Bounded
    Context Bounded
    Context
    Bounded
    Context
    Bounded
    Context
    https://thedomaindrivendesign.io/bounded-context/

    View full-size slide

  60. @MarcDuiker 67
    Ecommerce
    Product
    Catalog Pricing
    Billing
    Shopping
    Basket
    https://thedomaindrivendesign.io/bounded-context/

    View full-size slide

  61. @MarcDuiker 68
    “Ubiquitous language identifies the terms
    and concepts within a bounded context that
    are unambiguous and agreed upon by all
    stakeholders.”
    https://thedomaindrivendesign.io/what-is-strategic-design

    View full-size slide

  62. @MarcDuiker 69
    Billing Shopping Basket
    https://thedomaindrivendesign.io/what-is-strategic-design

    View full-size slide

  63. @MarcDuiker 70

    View full-size slide

  64. @MarcDuiker 71

    View full-size slide

  65. @MarcDuiker 72

    View full-size slide

  66. @MarcDuiker 73
    Bounded
    Context
    Bounded
    Context

    View full-size slide

  67. @MarcDuiker 75
    “Resilience is the ability to provide and
    maintain an acceptable level of service in
    the face of faults and challenges to normal
    operation.”
    https://en.wikipedia.org/wiki/Resilience_(network)

    View full-size slide

  68. @MarcDuiker 76

    View full-size slide

  69. @MarcDuiker 77
    https://learn.microsoft.com/en-us/azure/architecture/patterns/

    View full-size slide

  70. @MarcDuiker 78

    View full-size slide

  71. @MarcDuiker 79

    View full-size slide

  72. @MarcDuiker 80
    Function App B
    Function App A Queue Storage

    View full-size slide

  73. @MarcDuiker 81
    public static class ChainingWithRetryExample
    {
    [FunctionName(nameof(ChainingWithRetryExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var resultA = await context.CallActivityWithRetryAsync(
    nameof(ActivityFunctionA),
    new RetryOptions(TimeSpan.FromSeconds(5), 3) { BackoffCoefficient = 2 },
    null);
    var resultB = await context.CallActivityAsync(
    nameof(ActivityFunctionB),
    resultA);
    var resultC = await context.CallActivityAsync(
    nameof(ActivityFunctionC),
    resultB);
    return resultC;
    }
    }

    View full-size slide

  74. @MarcDuiker 82
    public static class ChainingWithRetryExample
    {
    [FunctionName(nameof(ChainingWithRetryExample))]
    public static async Task RunOrchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
    var resultA = await context.CallActivityWithRetryAsync(
    nameof(ActivityFunctionA),
    new RetryOptions(TimeSpan.FromSeconds(5), 3) { BackoffCoefficient = 2 },
    null);
    var resultB = await context.CallActivityAsync(
    nameof(ActivityFunctionB),
    resultA);
    var resultC = await context.CallActivityAsync(
    nameof(ActivityFunctionC),
    resultB);
    return resultC;
    }
    }

    View full-size slide

  75. @MarcDuiker 84
    Increase number of (virtual) machines Increase CPU / memory of one machine

    View full-size slide

  76. @MarcDuiker 85

    View full-size slide

  77. @MarcDuiker 86

    View full-size slide

  78. @MarcDuiker 87

    View full-size slide

  79. @MarcDuiker 88
    scale out scale out

    View full-size slide

  80. @MarcDuiker 89
    scale out
    scale out
    https://learn.microsoft.com/en-us/azure/azure-functions/functions-scale#scale
    Use dedicated
    resource to its
    fullest

    View full-size slide

  81. @MarcDuiker 90
    scale out scale out
    https://learn.microsoft.com/en-us/azure/azure-functions/functions-scale#scale
    Use higher tier / sku
    Use regular tier / sku

    View full-size slide

  82. @MarcDuiker 91
    App Settings:
    FUNCTIONS_WORKER_PROCESS_COUNT
    Function App resource property:
    functionAppScaleLimit
    https://learn.microsoft.com/en-us/azure/azure-functions/event-driven-scaling
    https://learn.microsoft.com/en-us/azure/azure-functions/functions-best-practices
    SCALE_CONTROLLER_LOGGING_ENABLED

    View full-size slide

  83. @MarcDuiker
    - Monitor your agility!
    - Ask yourself these questions before adding any code:
    - Do *I* need to write this?
    - Is this a good fit with the rest of the app?
    - What is the impact regarding resilience/scalability
    of the app?

    View full-size slide

  84. @MarcDuiker
    linktr.ee/marcduiker

    View full-size slide