NodeDay 2014: Micro-services in Node.js
Akbar S. Ahmed |
Apr 25, 2014
Micro-services in Node.js
in very small amounts of code. Node.js lets you write server-side code in tiny
mind-size pieces. We call them micro-services. Stop writing monolithic web apps!
Break everything apart. Do one thing and do it well. You can run hundreds of
Node processes. It’s cool.
Richard discussed a different way of structuring Node apps with something he
termed micro-services. This talk is definitely worth listening to when the
video come out.
He believes in micro-services which is something that he discovered by accident.
Micro-services are super small node services that pass messages between other
- lots of processes also means you can run things in parallel
- also get good isolation
- micro-services are small
- micro-services are single purpose
- micro-services use messages to communicate
- there are many of them
- death of processes is expected
- 100 lines of code = a few screens to scroll
- can fit inside your head
use node modules
- prefer composition of libraries vs. complete framework
- do one thing and do it well!
anti-pattern: the orchestator
- a service that mediates
- a service that knows about other services
- each service should only know about its inputs and outputs
solution - communicate with messages
- what you should do is publish messages onto a service bus
- standalone information
- you can pattern match the message
- messages define the interface
- the transport mechanism is not important - instead think about messages going
- transport could be http or message queue
- no need for complex rules
- do named keys have given values?
- use MUST IGNORE semantics. This makes your world extendable.
- write your services so they can restart cleanly
- node best practice === die on uncaught exceptions. So expect to die.
How do you give node enterprise grade reliability?
Basically, randomly kill your process and ensure that your application is
written such that the user sees no impact.
Netflix has a tool to simulate failure called
Micro service architecture
- make decisions later, with more information
- calibrate quality and performance
- makes rewrites cheap
- avoid project mgmt ceremony
- services are the right size for humans
- too many unit tests makes rewrites expensive
When you have more information later in the project you can:
- split services
- combine services
- add services for special cases
- extend messages with more context
services are a comfortable size
- lets you focus effort where it counts
- analyze time, scale, domains
- keep everything in process during development
- delay the choice of a transport layer
- for direct connections use http
Monitor business outcomes not technical information.