[아티클 리뷰] MSA 제대로 디자인하기 Design Microservice Architectures the Right Way- Michael bryznek
후기
이 발표 영상이 제일 헛웃음이 나왔다
모든것을 사람의 손에 맡기지 않고 JSON 스펙에 따른ODE GENERATION으로 해결한다.
선언적인 API, 어떻게 진화할까 궁금하다.
Great Architecture vs Not so Great Architecture
Scales Dev Teams | Near term Velocity
Delivers Quality | Future Paralysis
Enables High Performance/ Low Cost
Supports Future Features Naturally
Misconceptions
Microservices enable our teams to choose the best programming langs and frameworks for their tasks
Reality:
We'll demonstrate just how expensive this is.
Team size and investment are critical inputs.
Google has 8 langs and 32000 employees
virtually, 1 lang / 4000 employees
Code generation is Evil
Reality:
What's important is creating adefined schema that is 100 % trusted.
Schema that is 100 % trusted.
We'll demonstrate one technique leveraging code generation
The Event Log Must be the Source of Truth
Reality:
Events are critical parts of an interface.
But it's okay for services to be the system of record for their resources.
Developers can maintain no more than 3 services each
Reality:
Wrong Metrics; we'll demonstrate where automation shines
Flow devs maintain ~5 services
Weekly maintenance <5% of time
Only one set of APIs and Events in Flow
How: Forms are used to create instances of rscs
API Definition
Language Neutral in JSON
Everything is resources
Annotations included easily for GDPR
How: Resource Oriented
Expose User's rsc by providing operations
get by id
post of user form
How: Definitions in Git, with CI
Modify JSON and pull → triggered CI
Set of linters run on these JSON
how: Tests Prevent Errors
Verify Potential braking changes during API Design Phase
how: API Implementation Supported by Code Generation
Grpc→ code generation
specifications is the first thing we build
how: Code Genration: Routes
Absolute certainties specs matches implementations
Built by one person feelings with consistent namings
how: Code Generation: Client
Optimize things to make it possible
Implementations should be so nice so that devs wouldn't dev on them
how: Mock Client
Compiles and fully functional
High fidelity and fast testing
Sufficiently prove that testing works
Mock client + extra to make them work
Only 2 cases where it is not caught on by mocks (networking)
how: Implementation
Same awesome codes all micro services
Database Architecture
Each microservices app owns its database
No other service is allowed to connect to the database
It is a np problem to prove that the db is correct ⇒ insiduous tech debts
Other services use only the service interface (API + Events)
HOW: Create a Database
This is the only way to establish a database.
entering "dev" returns help of this tool
All databases are following the same db naming conventions make the users understand the system better
One person knows all and other people benefit from their works
How: Define storage req in metadata
Describe "scala" req
Describe "psql" req
Code generate the table definition
Code generate the data access obj
Note data tier independent from API
Just uses the same tool chain
How: Code generation: Create a Table
No empty string
Consisten chekcs, meta data
Enable global features like 'hash_code' to minimize the writes
Ops hashcoded set to minimize the writes
Creating dbs do not need a creativity strictly enforced
How: Code generation: Scala Class
Normalize access to DB
indexes on ids, email, hasEmail, ... using findAll
Ensure proper indexes exist from start
One way to do it is that you index for what you want for retrieval.
Devs will go in and use find_by_email method
We have caught it in the beginning of dev process
How: Automated Tests:
How: Test Resource Ops
Use the generated mock clients to write simple tests
Continous delivery is a prerequisite to managing micro service architectures
Deploy triggered by a git tag
Git tags created automatically by a change on master (ex merge PR)
100 % Automated, 100 % reliable
It took one person to build CD entirely
Microservice Infrastructure — keep it simple
Let the experts do this for you
Standard Health Checks
Events
We have an amazing API, but please subscribe to our event streams instead.
They consumes events mostly
Can use API but usually use events more
Principles of an Event Interface
gRPC(binaries) — forcing devs to use code generation to consume events to depict the events are awesome
Correctness is important to keep the specs in prod and current specified specs
They use Kinesis
We emphasize simplicity
Events: Approach
Producers:
Create a journal of ALL ops on table
All the insert, deletes along with the ops
Record Ops (Insert, Update, Delete)
On creation, queue the journal record to be published
Real time, async, we publish 1 event per journal record
Enable replay by simply requeuing journal record
Consumers:
Store new events in local db, partitioned for fast removal
On event arrival, queue recrod to be consumed
Process incoming events in micro batches (250 ms)
record failures locally
You don't have to go to kinesis or journal
You have a copy of it in local
Events: Schema First
They use api builder here as well.
This goes through linters as well
user_event → naming convention
1 model/ event
N events in one union type
1 union type /stream
Stream owned by 1 service
Most services define exactly 1 stream
Events: Schema Linter
timestamp
orgs
ALL the events will look the same
same structures
Consistencies let you do a lot of interseting things
Producers: Database Journal
Document retention period
Code generate journal
Use Partitions to manage stroage
Producers: Streams
Devs should feel easy to use it
All the app codes will look very similar to these
Any microservices will be relevant because it behaves the same
Other than domain knowledge and context
Producers: Testing
This works on prod
High fidelity testing
Consumers Testing
End to end test
easy
Dependencies
Goals: Automatically update all services to latest dependencies
Critical for security patches / bug fixes in core libs
Takes hours (not weeks or months)
Same process for internally developed libs and open src
Flow: we upgrade all services every week to latest dependencies
Keep things up to date
Dependencies: Tracking
Git hub extract all libs and binaries
Crawls all of them and keep tracks of them
Event stream to you to provide these recommendations
Version tag parsers in Scala combinators
These works perfectly without false positive
Totally worth it.
Recommended Upgrades packages
Recommendations
Dependencies
Dependencies: Updating
one command to do this
Dependencies & Continous Delivery
deploy once the build passes
Summary
Design schema first for all APIs and Events
consume events by default
Invest in automation
deployment, code generation, dependency management
Enable teams to write amazing and simple tests
drives quality, streamlines maintenance, enables continous delivery
TDD in Prod
looks amazing
tests run as cronjobs
How to manage features and different branches and CD?
Every features are usually factored in.
Open Pull Requests are not going to be existent
When you are done it is in prod
Everyday implementations need to be decomposed and pulled in.
Feature flag that is enabled and prod will use it.
Last updated