why they are still important in the microservice era
Once upon a time,
there were only monoliths
your application was written in a one repo
and the deployment was simple
We know how to structure the code
We know how to test the code
We know how to deploy our application
We know how to monitor our application
We know how to improve performance
We know how to add new feature
More than 20 years of knowledge
Erich Gamma
Richard Helm
Ralph Johnson
John Vlissides
Factory
Builder
Singleton
Adapter
Facade
Proxy
Iterator
Observer
Strategy
Visitor
Know which domains are involved
Choose which µs should scale up
Find the common needs to refactorize them
Consistent deployment system
Decorators
Encapsulation
// Injection
fastify.decorate('myObject', new MyObject({ /* ... */ ))
fastify.decorate('myCounter', 0)
fastify.decorateRequest('getUserId', function () {
return this.headers['mia-user']
})
// Usage
fastify.get('/', myHandler)
function myHandler (request, reply) {
const userId = request.getUserId()
const result = this.myObject.getResult()
reply.send(result)
}
fastify.register(plugin1, { prefix: '/plugin1/' })
fastify.register(plugin2, { prefix: '/plugin2/' })
// Plugin1
function plugin1 (fastify, o, n) {
fastify.decorate('myObject', new MyObject({ /* ... */ })
fastify.get('/', myHandler)
}
// Plugin2
function plugin2 (fastify, o, n) {
fastify.decorate('myObject', new MyObject({ /* ... */ })
fastify.get('/', myHandler)
}
User
UserService
UserClient
HTTP routes
Tweet
TweetService
TweetClient
HTTP routes
Follow
FollowService
FollowClient
HTTP routes
Timeline
TimelineService
HTTP routes
Fastify