Slide 1

Slide 1 text

Pragmatic Serverless Azure: SPAs, Microservices & gRPC with .NET Christian Weyer https://thinktecture.com/christian-weyer @christianweyer Co-Founder & CTO

Slide 2

Slide 2 text

2 Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET § Co-Founder & CTO at Thinktecture AG § Personal focus on § Mobile & web-based application architectures § Interoperability, cross-device § Pragmatic end-to-end solutions § Cloud-native & serverless architectures § Independent Microsoft Regional Director § Microsoft MVP for Developer Technologies & Azure ASPInsider, AzureInsider § Google GDE for Web Technologies, Angular [email protected] @christianweyer https://www.thinktecture.com Christian Weyer

Slide 3

Slide 3 text

3 § Server-side [micro]services with APIs § Written in C# with .NET § Exposing Web APIs § Web-based clients § JavaScript-based SPAs § Communication via HTTP § Running on-prem, hosted, or in public Cloud § With or without containers § Infrastructure-focused Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Typical SPA architectures for modern business applications HTTP API WS API Service D HTTPS HTTPS WebSocket Service A Service B Service C HTTP API

Slide 4

Slide 4 text

4 § Building SPAs end-to-end § Often too complex, with different stacks → Improving needed knowledge & coding habits § SPA communication with server-side APIs/services § Thinking different in controlled environments → Improving the inner loop § SPA hosting in a serverless environment § Container-based development, deployment & operation → Improving the outer loop Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Reconsidering SPA architectures – in a pragmatic way Increased developer productivity (in controlled environments)

Slide 5

Slide 5 text

5 Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Three pillars One programming language & framework Strongly typed client-server communication No servers, no clusters

Slide 6

Slide 6 text

6 Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Three pillars One programming language & framework Strongly typed client-server communication No servers, no clusters

Slide 7

Slide 7 text

7 § Users want: § Cross-Platform, Cross-Device § No installations § Offline (important for many use cases) § Developers think: § Web is the solution, but web is different § SPA is the solution, but SPA is different § JavaScript seems to be an issue for lots of .NET developers § There is existing .NET code, what to do about it? § Which technologies to choose? § JavaScript, everywhere? C# & .NET everywhere? § In the Frontend: Can Blazor help here? Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET C# & .NET everywhere?

Slide 8

Slide 8 text

8 § Blazor is a family of web technologies § Server § WebAssembly § Blazor WebAssembly is a SPA framework § Web, SPA & distributed computing knowledge § HTML, CSS knowledge § DOM knowledge § JavaScript for DOM interaction & 3rd party integration § C# & .NET Standard for client-side logic → Full-stack C# possible Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET What is Blazor? Mono-based Runtime .NET CLR .NET 6 .NET Framework Blazor WebAssembly Blazor Server Razor Components Browser (WASM / .NET / JS) Browser (JS Stub) Server (.NET)

Slide 9

Slide 9 text

9 Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET WebAssembly browser support https://caniuse.com/#feat=wasm

Slide 10

Slide 10 text

10 Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Blazor WebAssembly in the browser Blazor DOM Web Assembly .NET Razor Components

Slide 11

Slide 11 text

11 Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Three pillars One programming language & framework Strongly typed client-server communication No servers, no clusters

Slide 12

Slide 12 text

§ JSON major data exchange format § Great tooling § Can handle arbitrary binary data § Highly interoperable § RPC-ish in many cases § JSON text format can be verbose § Compression is usually a must § Not every MEP can be easily implemented § Loosely typed § Open API can help here Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Reconsidering Web APIs as service interfaces § Let’s just call them Web APIs (RPC-ish, REST etc.)

Slide 13

Slide 13 text

13 § In Web Services world, we did a lot of contract-first (XSD, WSDL) § In Web API world, we do a lot of code-first (OpenAPI showed up later) Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Service interface modeling: Code-First vs. Contract-First § Code-First § Agile, by writing platform code § Contract gets derived or generated from code § May not lead to highest interoperability § Contract-First § Specification before implementation § Platform code gets generated from contract description § Formal way to ensure highest interoperability

Slide 14

Slide 14 text

14 § Initially created for synchronous [micro]service-to- [micro]service communication § WCF, anyone? § Its presence increases steadily § Some people like to use gRPC between frontends and backends, as well § Uses HTTP/2 & Protocol Buffers § gRPC is contract-first Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET gRPC

Slide 15

Slide 15 text

15 Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET ProtoBuf (Protocol Buffers) § Language-neutral, platform-neutral, extensible mechanism for describing & serializing structured data § Like XML/XSD, but smaller, faster, and partly simpler § Uses integer tokens to identify members, not names § Support for code generation for many languages, including C# § Also: Binary representation on the wire message Person { required string name = 1; required int32 id = 2; optional string email = 3; }

Slide 16

Slide 16 text

16 § .NET supports gRPC since .NET Core 3.0 § Contract-First: You need a .proto file first § C# code gets generated when the .proto file changes § “Add Service Reference…” in VS can handle the client side for you § Implement gRPC service based on generated base class § Get typed client proxy generated on the client side based Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Contract-First gRPC in .NET

Slide 17

Slide 17 text

17 § Browsers are the de-facto frontend platform today § Native gRPC does not work in browsers (due to restrictions for HTTP/2 framing in browsers) § gRPC-Web is implementation of gRPC for browser clients § gRPC-Web clients connect to gRPC services via a gRPC-Web proxy § .NET offers § Server-side middleware for proxy § Client library (beyond JavaScript) § Unary calls & server-streaming supported Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET gRPC-Web

Slide 18

Slide 18 text

18 § We can have gRPC in .NET without having to write .proto files § Improving the inner loop § Open-source community project protobuf-net.Grpc § Builds on WCF contract semantics § ServiceContract, DataContract § Proto* attributes offer finer control § Implement gRPC service based on .NET interface § Get strongly-typed client proxy at runtime based on .NET interface, e.g., in Blazor Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Code-First gRPC(-Web) in .NET & Blazor

Slide 19

Slide 19 text

19 Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Three pillars One programming language & framework Strongly typed client-server communication No servers, no clusters

Slide 20

Slide 20 text

20 Serverless Programming Model (FaaS) § Event-driven § Stateless § Service-full Operational Model § Fully managed § Automatically scaling § Usage priced SPAs, Microservices & gRPC with .NET Pragmatic Serverless Azure

Slide 21

Slide 21 text

21 § Containers provide a common set of interfaces and defined execution environment § Docker today § Maybe WebAssembly tomorrow § Containers homogenize the development, testing, and operation of applications § On-prem or in Cloud § Orchestrators like Kubernetes handle complex multi-container scenarios for high availability & high scale scenarios Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Containers

Slide 22

Slide 22 text

22 § No real serverless mode & pricing for Azure Kubernetes Service (AKS) § There is cluster autoscaling and other features, though § It’s hard to find, and hire people that really know Kubernetes § Kubernetes itself can become complex § Sometimes, Kubernetes is an overkill § In the end, we want to develop software solutions Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Containers & orchestrators in Azure

Slide 23

Slide 23 text

Azure landscape for containers Azure Kubernetes Service Azure WebApps for Containers Azure Container Instances Azure Container Apps SPAs, Microservices & gRPC with .NET Pragmatic Serverless Azure

Slide 24

Slide 24 text

24 § Serverless platform to run containerized applications § Charged on actual compute allocation (consumption) § Built on top of open-source projects § Kubernetes/AKS, KEDA, Envoy, Dapr § Hides most of Kubernetes/AKS complexity Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Azure Container Apps (ACA)

Slide 25

Slide 25 text

25 § Using GitHub Actions for building containers & deploying to ACA § Including new revisions Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Serverless deployment to Azure Container Apps

Slide 26

Slide 26 text

26 § SPA architectures reconsidered (in controlled scenarios) § Blazor WebAssembly gives us C# & .NET power for SPAs in the browser § ASP.NET Core gives us gRPC & gRPC-Web power for SPA-to-service communication § Azure Container Apps give us powerful serverless hosting & execution for container-based applications Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Summary

Slide 27

Slide 27 text

Thank you! Christian Weyer https://thinktecture.com/christian-weyer @christianweyer [email protected] Demo: https://github.com/thinktecture/blazor-wasm-grpc-code-first Blazor Knowledge Hub: https://www.thinktecture.com/de/asp-dotnet-core-blazor/ Articles about Blazor, PWA, Web Components, Angular, .NET Core & more: https://www.thinktecture.com/en/newsletter

Slide 28

Slide 28 text

28 § ASP.NET Core Blazor § https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor § Protocol Buffers § https://developers.google.com/protocol-buffers § gRPC § https://grpc.io/docs/what-is-grpc/introduction/ § https://grpc.io/docs/languages/csharp/basics/ § gRPC in .NET Core § https://docs.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start § gRPC-Web in .NET Core § https://docs.microsoft.com/en-us/aspnet/core/grpc/browser § gRPC Code-First in .NET Core § https://github.com/protobuf-net/protobuf-net.Grpc § All-the-things Azure Container Apps § https://www.thinktecture.com/de/azure/webinar-azure-container-apps/ Pragmatic Serverless Azure SPAs, Microservices & gRPC with .NET Resources