20 TIPS FOR BUILDING A SCALABLE AND ROBUST NODE.JS STACK THAT DEVELOPERS LOVE
@
Patrick Steele-Idem
@psteeleidem
github.com/patrick-steele-idem
Senior Platform Architect @
These tips are based on lessons I learned from building and supporting web development stacks for both the JVM and Node.js in companies big and small.
AVOID “MAGIC”
If developers cannot reason about a system then they will not be happy or productive
MORE ON MAGIC…
• What is Magic?
• Runtime code that changes how other code runs
• Non-obvious and overly clever tricks• Abstractions and indirections
• Avoiding Magic:
• Prefer explicit over implicit• Code comments and clear documentation
KEEP DOCUMENTATION WITH THE CODE
The documentation you are reading is out-of-date and confusing.
Would you like to like to continue?
README files for the win. Learn Markdown. Branch docs with code.
DON’T FORK THE COMMUNITY
How many package managers do you really need?(I’m looking at you Bower, Component, Ender, Jam, etc.)
GIVE DEVELOPERS CHOICES
Don’t build a restrictive framework!
KEEP AN EYE ON THE FUTURE
Do not become too attached to today’s technologies and practices
THINK MODULAR, NOT MONOLITHIC!
Image Source: http://www.flickr.com/photos/albatros/
Much easier to digest small, bite-sized modules compared to a monolithic framework
MULTI-VERSION WITHOUT CONFLICTS
Image Source: http://www.flickr.com/photos/albatros/
Do not force everyone to agree on the same version of a module! Dependencies are your friends.
FOLLOW SEMANTIC VERSIONING
• Increment MAJOR version when you make incompatible API changes,
• Increment MINOR version when you add functionality in a backwards-compatible manner, and
• Increment PATCH version when you make backwards-compatible bug fixes.
• Notes:
• 0.x.y – Anything goes• Pre-release labels to indicate “beta” versions
• More info:
• http://semver.org/
ENCOURAGE A MODULAR DIRECTORY STRUCTURE
Organizedby Modules:
Organized by MVC and Resource Type:
ENABLE AUTO RESTART AND LIVE CODING
Minimize time spent bouncing between windows and waiting.Make sure server startup time never exceeds 2s.
http://www.flickr.com/photos/mbiebusch/
AVOID THE BUILD STEP
In development, do as much at runtime as possible.
http://xkcd.com/303/
INTERNAL OPEN SOURCE
Cultivate a culture of collaboration within a company and break down cross-team boundaries
PROVIDE AN INTERNAL SUPPORT FORUM
Empower and encourage users to help each other. Redirect emails to the support forum. Redirect open
source questions to public support forums.
Image Source: http://www.flickr.com/photos/31065898@N08/
DON’T BUILD A STACK IN ISOLATION
Work in conjunction with an application team to build a new stack.
Image source: http://www.flickr.com/photos/epublicist/
BE HELPFUL WITH ERROR MESSAGES
MY APPLICATION STOPPED WORKING AND WE LOST A TON OF MONEY
BUT I FOUND A VERY HELPFUL MESSAGE IN THE SERVER LOGS, SO I’VE GOT THAT GOING FOR
ME, WHICH IS NICE.
Expect services to go down. Expect bad input. Catch errors early. Log the full stack trace.
GO REACTIVE
React to events. React to load. React to failure. React to users.
Which is worse, a service that fails fast or an unresponsive service?
Write tests and find out.
http://www.reactivemanifesto.org/
http://www.flickr.com/photos/dougww/
MANAGE WORKER STATE
Start
Warm-up
Put into Traffic
Unhealthy
Take out of Traffic
Kill
Proactively handle garbage collection, errors and high CPU and memory usage
Do not forget this step!
Be proactive
Be able to detect
AVOID “BLOCKING” MIDDLEWARE
Middleware should not add significant overhead to every request.
20ms 40ms 60ms 80ms 100ms
Page Controller
Middleware Your Code
SUPPORT ASYNCHRONOUS RENDERING
HTMLTemplate
Sy
nc
hro
no
us
As
yn
ch
ron
ou
s
View Model
No Delay
Data Providers
1. Setup data providers2. Go straight to the
template!
ControllerInput
HTMLTemplateView Model
Long Delay
ControllerInput
1. Make service calls2. Wait for all data to come
back3. Prepare view model
PROVIDE A COMMAND LINE TOOL
Easily support environment setup, app creation, deployment, scaffolding, upgrades, etc.
QUESTIONS?
[email protected]@psteeleidem
EVALUATE THIS SESSION
Sign-in: www.eclipsecon.org
Select session from schedule
Evaluate:
1
2
3
Top Related