Forward 4, 2016-02-10
This is not a talk about code
This is about architecture
Service Oriented Architecture
- What is it
- Why use it
- Why do it in node?
- How to do it properly
- How npm uses SOA
Confession time
I rewrote this whole talk yesterday.
Part 1: what is SOA?
SOAs are a distributed system
Distributed systems feature:
- Concurrency
- No global clock
- Independent components
What about microservices?
Part 2: advantages of SOA
-
technical
-
organizational
Resource efficiency
Cost efficiency
-
specialization
-
scalability
-
tunability
Robustness
Never gonna give you up,
never gonna take you down.
Robustness
0.01^100 = 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001%
100 boxes, 1% chance of failure
Chance of being completely down:
0.01*100 = 100%
Chance of being slightly down:
Debuggability
Organizational advantages
Conway's Law in reverse
Simpler systems are simpler
Smaller systems allow for smaller teams
Smaller teams are better teams
Big teams are hard, so don't have any.
Part 3: why node is great at SOA
#1: Node is inherently good
at writing web services
#2: small modules make for efficient microservices
#3: node and npm make shared logic easier
and now, a shameless product plug
Share code within your company using npm On-Site, or npm Organizations
Part 4: best practices for SOA in node
- application-level
- architectural
- operational
Application level
Isolation
Consistency
- access-cache
- billing-api
- docs
- frontdoor
- partners
- registry-relational
- user-acl
- validate&store
- www
- downloads-api
- fastly-purge
- login-cache
- public skimdb
- search
- tarball follower
- credentials follower
- slackboard
npm's services
Consistent error handling
- crash on error
- restart on crash
- monitor restarts
Shared logic
The less unique code, the faster the fix.
Architectural
Asynchronous operations will save your life
Fail safely and softly
- Expect flaky networks
- Degrade gracefully
- Recover automatically
Race conditions
conditions. So race many
Operational
Configuration
- one source of truth
- configure at deploy
Deployment
- automate everything
- use "canary" servers
Handle cold starts
- Can the service deploy if it's down?
- Will creep up on you slowly
Metrics
- Capture every request
- source
- frequency
- size
- Log every response
- type
- speed
- size
- Log every event
Monitoring & Alerting
- Dashboards: not just for show
- Alert on out-of-range metrics
Part 5: npm as SOA
A case study
What is npm?
4 things:
- CLI
- Registry
- www
- On-Site
Fun fact
One thing
One big, complicated thing
The CLI
The Registry
More registry
Followers
www
npm On-Site
Service re-use
Takeaways
- SOA is neat
- Node is good at SOA
- You can be good at SOA
- npm is pretty neat, too
Thank you!
laurie@npmjs.com
Twitter: @seldo
Forward: Node, npm and SOA
By seldo
Forward: Node, npm and SOA
- 5,938