[go: up one dir, main page]

0% found this document useful (0 votes)
714 views21 pages

Building Microservices With .NET Core

The document discusses reactive microservices using .NET Core. It defines a microservice as a discrete unit of functionality adhering to the single responsibility principle. It then discusses challenges like distributed transactions, complex data flows, and lessons learned from building a sample grocery ordering application ("Partial Foods") with microservices architecture implemented with gRPC, event sourcing, and shared-nothing design. The presentation emphasizes embracing proven solutions for challenges like discovery, logging, security rather than reimplementing them.

Uploaded by

Mohammed Khanjri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
714 views21 pages

Building Microservices With .NET Core

The document discusses reactive microservices using .NET Core. It defines a microservice as a discrete unit of functionality adhering to the single responsibility principle. It then discusses challenges like distributed transactions, complex data flows, and lessons learned from building a sample grocery ordering application ("Partial Foods") with microservices architecture implemented with gRPC, event sourcing, and shared-nothing design. The presentation emphasizes embracing proven solutions for challenges like discovery, logging, security rather than reimplementing them.

Uploaded by

Mohammed Khanjri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Reactive Microservices

with .NET Core


Kevin Hoffman
Lead Engineer, Capital One
@KevinHoffman autodidaddict
About Me
Agenda
● What is a microservice?
● Distributed Transactions
● Complex Data Flow Modeling w/Microservices
● 100% Fully Buzzword Compliant Demo
○ Not a “hello world” sample
● Lessons Learned So Far
● Q&A
Is this a Microservice?
[Route("api/[controller]")] This is a protocol
public class ValuesController : Controller handler … a facade.
{
// GET api/values This is not your
[HttpGet] service.
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}

// PUT, POST, DELETE, etc


...
}
Some microservices are RESTful …
Not all RESTful services are micro
The Microservices Onion Storage

Metrics /
Protocol Monitoring

Discovery
Elastic Scaling

Service Tracing
0 Downtime
Deploy

Security
Logging

Networking
What is a Microservice
A microservice is a discrete unit of functionality that adheres to the Single
Responsibility Principle, asks nothing* of its host, and can be deployed without
impacting other services in the ecosystem.

You are here


But...I must worry about the onion...right?
● Discovery - Steeltoe + Eureka, Consul, DNS
● Logging and Monitoring
○ Splunk, Sumologic, Grafana, App dynamics, Prometheus, Dynatrace, ad nauseum
● Security - OAuth, OIDC (DIY middleware, third party middleware, Azure)
● Protocol and Transport - HTTP, gRPC, Protobufs, JSON
● Configuration - Spring Config Server (via Steeltoe), etcd, env vars, ...
● 0 Downtime Deploy - Kubernetes, Cloud Foundry, GKE, etc
○ Containerize your app
● Tracing - Steeltoe + Zipkin, OpenTracing, Jaeger, ...
● Storage - Cloud platform, S3, ...
● Elastic Scaling - Kubernetes, EKS, Cloud Foundry, GKE, etc
○ Containerize your app
● Messaging - Rabbit, SQS, Azure, Kafka, PubNub, ...
Embrace the onion… trust the onion...
● Focus on your service, trust the onion layers
● Let the experts do what they do best
● Use professional-grade wheels, don’t re-invent your own
○ Unless your core business makes money from the sale of wheels
● Cloud platforms are plentiful, available, and mature.
○ Rely on them wherever you can
● If your service is buggy or broken, none of these onion layers can save you.
Too much worrying about outer layers is a smell
Sidecar… onions … Side-onions!

You are here


Classic Distributed Transaction
Create
Order

Request App
Reduce
Inventory

Update
Ledger
Distributed Failure via Microservices
Inventory
Service

Gateway/
Request Agg Product
Service Service

Ledger
Service
Immutable Events and Shared-Nothing Activity Modeling

Orders Inventory Ledger

Order Accepted Inv Reserved Order Accepted

Inv Reserved

Order Canceled Inv


InvReleased
Shipped Order Canceled

Inv
InvReleased
Shipped

Life Beyond Distributed Transactions - http://queue.acm.org/detail.cfm?id=3025012, Pat Helland


Facts vs State

FACT STATE

Order Created @ 2:12PM by “bob” Order { ID = 12, Status = Open, … }

Inventory Reserved SKU 12345 Eventual Item 12345 { WarehouseQty = 99 }


Consistency
Inventory Reserved SKU 12345 Item 12345 { WarehouseQty = 98 }

Order 12 Canceled @ 9:21PM by Order { ID = 12, Status = Canceled,


“bob” …}

Inventory Released SKU 12345 Item 12345 { WarehouseQty = 99 }


Being right 5 seconds from
now is always better than
being wrong right now.
Partial Foods - Sample Application
● Transactions modeled as immutable activities
● State exposed as eventually consistent, materialized views
● Designed for Scale, Throughput, Durability, Reliability
● More than just “Hello World”
● Online Store
○ Sells groceries
○ Orders fulfilled asynchronously
○ Inventory releases and holds
○ Order creation and cancellation
○ Durable message broker
“Partial Foods” - Microservices Architecture

API Order
REST/JSON Service Command

Order
Mgmt

Ledger
Inventory
● gRPC Services
● Pub/Sub Messaging
○ Kafka

Partial Foods
● Entity Framework Core 2.0
○ Postgres
● Eventual Consistency
Sample App Demo ● Modeling Activities instead of
& Distributed Transactions
Code Walkthrough ● Embrace Shared-Nothing
Recap / Lessons Learned
● Not all microservices are RESTful JSON services
○ Show gRPC some love
● Modeling entities and immutable, distributed activities can be a simple solution to a complex
problem
○ Event Sourcing and CQRS are for more than just Netflix
○ Get it working first, materialize your views later.
● .NET Core 2.0 is excellent, and ready for production.
○ 2.0 tooling is superb, 1.x … not so much
● Containerize your workloads
● Build cloud-first or cloud native
○ Kubernetes, Cloud Foundry, AWS, Azure, Google Cloud, etc.
○ 12/15 factors
● Microservices are an architectural pattern, NOT a framework/library
○ Nor are they a panacea
● Disappointed that Partial Foods doesn’t have a proper logo
Q&A
● Twitter @KevinHoffman
● Always available to chat
● Partial Foods Code
○ http://github.com/microservices-aspnetcore/partialfood-*
○ Requires Postgres, Zookeeper & Kafka, .NET Core 2.0
● Resources
○ grpc.io
○ https://kafka.apache.org/quickstart

You might also like