32
Building Microservices with .Net

Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Embed Size (px)

Citation preview

Page 1: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Building Microservices

with .Net

Page 2: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Vasilenko Anton.Net Team Leader

@ Binary Studio

Page 3: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Contents

1.Definitions2.Comparison with alternatives3.Key aspects in details

In theoryIn the real .Net solution

Page 4: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

“Microservices are ...

… small, autonomous services that work together.

Sam Newman

Page 5: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

“There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors.”

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”

Martin Fowler

Page 6: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

“Microservices ...

● application - a suite of small services

○ each in own process

○ communicating i.e. via HTTP

● built around business capabilities

● auto-deployed independently by CI & CD

● minimal centralized management

● different languages possible

● different data storages possible

Page 7: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Service Oriented Architecture

“A loosely-coupled architecture designed to meet the business needs of the organization.”

A software design based on discrete software

components, “services”, that collectively

provide the functionalities of the larger

software architecture.

SOA is an architectural style that supports service-orientation. Service-orientation is a way of

thinking in terms of services and service-based development and the outcomes of services.

Page 8: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

SOA vs Microservices

SOA

Microservices

Very broad term, almost meaningless

Page 9: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Monolith architecture

“All architectural layers and all functionality in one single application.”

Simple to:● Develop● Deploy● Test … until it starts growing

https://youtu.be/wgdBVIX9ifA?t=1089

Page 10: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Let’s dive into details

Page 11: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

In theory✘ Separate projects✘ Identify seams✘ Isolate wisely

changing partsteam-wiseextra security, monitoring

Key points: Splitting the Monolith

In our project✘ Logical split✘ With scalability in mind✘ Isolate external services✘ several DBs

Page 12: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Key points: Splitting the Monolith

Summary✘ Do you really need to split?✘ Document API✘ Use different solutions, even for same

stack✘ Avoid using shared logic

“Don't even consider microservices unless you have a system that's too complex to manage as a monolith.”

Page 13: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

In theory✘ Prefer REST via HTTP✘ Facade services for 3rd-party API✘ Unified log data & format✘ Strangler pattern✘ Tolerant readers

Key points: Integration

In our project✘ Mostly HTTP, almost REST✘ Gateway Service✘ Tolerant readers (rest + json)✘ DB Integration✘ WCF (request-response, fire and

forget)

Page 14: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Key points: Integration

Summary✘ Better stick to HTTP with REST✘ Integration tests for 3rd parties✘ Avoid API versioning

Page 15: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

In theory✘ Centralized logging✘ Queryable log✘ Unified log data & format

Key points: Logging

In our project✘ Log from Cloud✘ Simple Filtering✘ Single format

Page 16: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Key points: Logging

Summary✘ Always store source module of

event✘ Use Correlation ID✘ Don’t reinvent the

Tools for logs: LogStash, Kibana.

Page 17: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

In theory✘ Blackbox tests of API✘ Generating tests by documented

API

Key points: Testing

In our project✘ UnitTests✘ Integration Tests✘ PostMan✘ WcfTestClient

Summary✘ Local debug environment (with faked

boundaries)✘ Simple test utility to test API

Page 18: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

In theory✘ Single Sign-On✘ Authorized Clients✘ Authorized Services

Key points: Security

In our project✘ Central identity & auth Servers✘ Everything authorized✘ Token in HTTP Header

identity and auth info

Summary✘ HTTPS is a MUST✘ Avoid sending auth info in token✘ Don’t reinvent the

Page 19: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

In theory✘ Single Sign-On✘ Authorized Clients✘ Authorized Services

Key points: Security

In our project✘ Central identity & auth Servers✘ Everything authorized✘ Token in HTTP Header

identity and auth info

Page 20: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Key points: Security

Summary✘ HTTPS is a MUST✘ Avoid sending auth info in

token✘ Don’t reinvent the

Page 21: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

In theory✘ Cloud should help you✘ If you help cloud

Key points: Scaling

In our project✘ Almost all services support

scaling✘ Sync through tricks with

MongoDB✘ Cloud support of scaling

Page 22: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Key points: Scaling

Summary✘ Microservice should be scalable✘ Think about DB bottlenecks✘ Think of data sync (DB, queues)

Page 23: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

In theory✘ Independent service deployment✘ ASAP✘ Use Cloud or containers features

Key points: Deployment

In our project✘ monolith deployment :(✘ Independent patching possible

✘ Cloud doesn’t encourage auto deploy

Page 24: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Key points: Deployment

Summary✘ Separate CI & CD jobs for each service✘ Deployment strategy

Page 25: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Our Learning path

Our project

Microservices

MonolythicApplication

Service-oriented Architecture

Page 26: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Monolith✘ Simplicity✘ Consistency✘ Inter-module refactoring

Monolyth vs MicroservicesMicroservices

✘ Partial Deployment✘ Availability✘ Help preserve modularity✘ Multiple Platforms (but please no

JS)

Remember my advices?

Page 27: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Microservices Trade-Offs

Page 28: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

What to Pick? What do we have?✘ Rapid Host Provisioning✘ Basic Monitoring✘ Rapid App Deployment✘ DevOps culture ...

What do we need?

Always consider✘ Solution scale✘ Teams configuration

Page 29: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Virtualization Containerization&

● Running on few hosts● Environment close to production● Easy management (with Cloud)

● Running on dev host● Environment close to virtual● Easy trace● Easy management (even without cloud)

Page 30: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Containerization with .Net

.Net stack usually requires Windows

Containers usually require UNIX

Page 31: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

Sources

1.“Building Microservices” by Sam Newman2.Enterprise Integration Patterns at camel.apache.org3.Microservices by Martin Fowler

a.Microservices Conf Video4.https://www.nginx.com/solutions/microservices/5.Majestic Monolith by David Heinemeier Hansson6.Our project source code and docs

Page 32: Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)

i.e.:✘You’ve said… Can you explain… ?✘What do you mean by …?✘Have you tried …?✘Can you suggest …?

Questions?