need to-know patterns building microservices - java one
TRANSCRIPT
![Page 1: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/1.jpg)
VINCENT KOK | ENGINEERING MANAGER, TRELLO | @VINCENTKOK
Need-to-Know Patternsfor building microservices
![Page 2: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/2.jpg)
Part-time speaker For fun and zero profit
About me: @vincentkok
Trello Engineering Manager on the
Trello team
Dutch You probably heard that already ;)
![Page 3: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/3.jpg)
Microservices Everybody seems to want them. Do we really know the impact of our choices?
Why do we want them so badly? Microservices are messy!
https://flic.kr/p/9u5pDA
![Page 4: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/4.jpg)
http://geek-and-poke.com/geekandpoke/2013/7/13/foodprints
![Page 5: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/5.jpg)
Grow Fat Code base grows. All
the things slow down.
Age Your code base will become a jurassic
park introducing new tech becomes hard
Ownership Who is responsible for which part and
more important: who has the pager
Economies of Scale
The bigger the team the more they
interrupt each other
Monolithical issues
![Page 6: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/6.jpg)
![Page 7: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/7.jpg)
8100Build jobs ran last week
![Page 8: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/8.jpg)
31992Automated tests
![Page 9: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/9.jpg)
Cause of issues can be extremely hard
![Page 10: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/10.jpg)
Who is having the pager?
INCIDENT RESPONSE
![Page 11: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/11.jpg)
Remember, we’re not all webscale
![Page 12: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/12.jpg)
![Page 13: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/13.jpg)
Optimise for rapid and sustainable flow of value.
DAN NORD
![Page 14: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/14.jpg)
![Page 15: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/15.jpg)
Small The size will be reasonable and
manageable
Independent lifecycle
Nothing will hold the team back. Go as
fast as you can
Optimise for the problem Pick solution and tech based on the problem at hand
Replaceable It is easier to replace if there is a need for
it
The microservice promise
![Page 16: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/16.jpg)
Patterns
Basics
Deployments
Testing
Security
Operations
https://flic.kr/p/9t2138
Decomposition
![Page 18: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/18.jpg)
Creating a call-out Watch the tutorial in the Presentation Guidelines to learn how to create call-outs on screenshots within this template.
![Page 19: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/19.jpg)
MINIMAL SERVICE
Health check 200 app is alive. 500 app is unhealthy, destroy the node
Stateless* Run as many nodes as you need
Expose a port Only access to the service
![Page 20: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/20.jpg)
DEEPCHECK
Deep check Quickly discover if a service
fails to connect to a dependency
![Page 21: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/21.jpg)
DEEPCHECK EXAMPLE
{ "avatar": { "details": { "avatarRepository": { "isHealthy": true }, "crowd": { "isHealthy": true }, "deadlock": { "isHealthy": true
![Page 22: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/22.jpg)
CODE & BUILDS
1 repository 1 build
![Page 23: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/23.jpg)
Libraries Feel free to use
shared libraries but keep them loose
Config Config is part of the service don’t have
dependencies
Schemas Make sure that
services are resilient to schema changes
Testing Test in isolation.
Keep them decoupled
![Page 24: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/24.jpg)
Strict separation of config from code.
12 FACTOR APP
![Page 25: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/25.jpg)
Redeploy Part of the service
configuration.
Configuration lifecycles
Instant change Switches you would like to
enable/disable straight away
Rebuild Rebuild to apply changes
![Page 26: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/26.jpg)
Treat them as cattle, not pets.
BILL BAKER
![Page 28: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/28.jpg)
Only one person There is only one person in
the team that owns it
Deployment smells
Takes more then 15 mins
Setting it up should be quick and initial deployment should
quick
Requires a ticket A ticket for the deployment
team
![Page 29: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/29.jpg)
Always deploy an empty service into production
ME AND PROBABLY OTHERS
![Page 30: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/30.jpg)
Developers in control
Artifact What is the artifact we’re running. We’re mostly standardising on Docker
Resources What resources are requires: RDS, SQS, Dynamo etc..
Compute What EC2 instance do we want how many of those and when to scale
Alarms What are the alarm thresholds for this service
Ownership Who is owning the service
Configuration We will be adding more icons as need arises. Speak up if in need!
![Page 31: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/31.jpg)
DECLARITIVE DEPLOYMENT
name: Confluencedescription: Confluence Cloudlinks: binary: type: docker name: docker.atlassian.io/confluence tag: latest healthcheck: uri: /wiki/internal/healthcheck deepcheck: uri: /wiki/internal/deepcheck semanticCheck: dockerImage:
![Page 32: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/32.jpg)
CONFIGURATION
config: environmentVariables: ASAP_AUDIENCE: "foo" ASAP_ISSUER: "foo" CONFLUENCE_VERTIGO_SMTP_HOST: "smtp.foo.com" CONFLUENCE_VERTIGO_SMTP_PORT: "587" LOG4J_EXTRA_RULES: "log4j.logger.org.hiberate=DEBUG"
environmentOverrides: staging: config: environmentVariables: ASAP_PUBLIC_KEY_FALLBACK_REPOSITORY_URL: "https://s3.amazonaws.com/keysto
![Page 33: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/33.jpg)
RESOURCES
resources: - type: sqs name: default attributes: MaxReceiveCount: 20 VisibilityTimeout: 60 scaling: instance: m3.xlarge min: 7
![Page 34: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/34.jpg)
SIDECARS
compose: pgbouncer: image: pgbouncer tag: ‘1.2’ ports: - 8091:91 - 8092:92
![Page 35: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/35.jpg)
500Services in production
![Page 37: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/37.jpg)
Testing microservices
![Page 38: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/38.jpg)
TESTING MONOLITHS IS EASY
![Page 39: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/39.jpg)
Unit
Integration
UI
![Page 40: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/40.jpg)
TESTING
Live service Test agains a real serviceMock service
Test against a mock service
![Page 41: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/41.jpg)
In process A local implementation of
your client
Out of process Use tools like WireMock and
MockServer
Two options
![Page 42: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/42.jpg)
MOCKING SERVICES - IN PROCESS
<beans profile=“integration-test"> <bean id="attachmentService" class=“c.a.attachment.AttachmentStub”/></beans>
![Page 43: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/43.jpg)
MOCKING SERVICES - WIREMOCK
{ "request": { "url": “/rest/api/content“, "method": “POST” "Accept": { "matches": “application/json” } }, "response": { "status": 200 }}
![Page 44: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/44.jpg)
Stable API If it is external it already
should have a CTK so rely on it
How to trust your mock?
Contract testing Internal fast moving API’s an
benefit from this
Rely on monitoring Small service, low MTTR
therefore low impact
![Page 45: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/45.jpg)
Semantic Check Automated test that runs against a node before it will be added to the load balancer
![Page 47: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/47.jpg)
OAuth 2.0 Grant a client access to
resources based on a newly created set of credentials
Common standards
OpenID Connect Identity on top of OAuth 2
OpenID Allows identity and some
metadata only
![Page 48: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/48.jpg)
How to secure a set of many services?
SECURING SERVICES
![Page 49: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/49.jpg)
ASAPAtlassian Service Authentication Protocol
![Page 50: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/50.jpg)
HOW DOES IT WORK?
Foo BarJWT
![Page 51: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/51.jpg)
WHAT’S INSIDE?
Foo Bar
{ "typ": "JWT", "kid": "foo/key1", "alg": "RS256"}{ "sub": “32769:87e…” "aud": "bar", "nbf": 1494284564, "iss": "foo", "exp": 1494284624, "iat": 1494284564, "jti": “961253cf-ac…”}
![Page 55: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/55.jpg)
50lbs
![Page 56: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/56.jpg)
Uptime of a system with 30 services of 99.99?
TRANSLATING THIS TO A MICROSERVICE ARCHITECTURE
![Page 57: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/57.jpg)
2 hours99.99 = 99.7
30
![Page 58: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/58.jpg)
Failure is imminent
RESILIENCE
![Page 59: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/59.jpg)
Circuit breakers Write code with failure in
mind
Three must haves
Request tracing Don’t spend hours debugging
Log aggregations Stream all logs into one
place.
![Page 60: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/60.jpg)
DO YOU KNOW YOUR SYSTEM?
![Page 61: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/61.jpg)
CREATE INSIGHT: AGGREGATED LOGGING
![Page 62: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/62.jpg)
Response times How much time do services spend calling other services.
Back pressure Stop putting pressure on a system that is in trouble and fail fast
Fallback How do you handle failure. A mandatory step in the programming model.
Circuit breakers
![Page 63: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/63.jpg)
CREATE INSIGHT: CIRCUIT BREAKERS
![Page 64: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/64.jpg)
Request TracingX-B3-TraceId : 1X-B3-SpanId : 1
X-B3-TraceId : 1X-B3-SpanId : 2X-B3-ParentSpanId : 1
X-B3-TraceId : 1X-B3-SpanId : 3X-B3-ParentSpanId : 2
X-B3-TraceId : 1X-B3-SpanId : 4X-B3-ParentSpanId : 3
![Page 65: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/65.jpg)
TRACE ID’S
![Page 66: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/66.jpg)
You Build It You Run It The team who builds it looks after it.
Ops Team Handover your services and let them
deal with the fun. Don’t do this.
![Page 68: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/68.jpg)
The monolith is deprecated
MAKE A STATEMENT
![Page 69: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/69.jpg)
A CONFLUENCE EXAMPLE
Core functionality
Scheduler
Attachments
Operational Transformation
Platform ServicesFront end
![Page 70: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/70.jpg)
Code Team is responsible for the codebase.Focus on
ownershipPipeline Team responsible for CI and Deployment
Incidents You built it you run it
![Page 71: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/71.jpg)
Decomposing core functionality
GraphQL service
![Page 72: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/72.jpg)
What should you take home?
Basics Services are cattle not pets.
Testing Testing a monolith is “easy” think about your service testing strategy
Deployment Deploying a service shouldn’t take longer then 15 minutes
Operations You build it you run it.
Security Think how you would like to secure service to service communications
Focus on value Optimise for rapid and sustainable flow of value
![Page 73: Need to-know patterns building microservices - java one](https://reader030.vdocuments.us/reader030/viewer/2022020119/5a64a71b7f8b9a27568b83eb/html5/thumbnails/73.jpg)
VINCENT KOK | ENGINEERING MANAGER, TRELLO | @VINCENTKOK
Thanks!