Studio
A nodejs framework to create decoupled and scalable applications
Install / Use
/learn @ericholiveira/StudioREADME
Studio.js
<img src="http://ericholiveira.com/studio/images/STUDIO_logo.png" align="right" width="300px" />Micro services framework for Nodejs.
Studio is a lightweight framework for node development to make easy to create reactive applications according to reactive manifesto principles. It uses micro-services (freely inspired by akka/erlang actors) implemented using bluebird a+ promises (or generators async/await) to solve the callback hell problem.
Do you want clusterization? Realtime metrics? Easy async programming? Completely decoupled services? Stop worrying about throwing exceptions? Then I've built this framework for you, because node needs a framework easy to use, yet giving your powerful features like realtime metrics and clusterization with no configuration (service discovery + rpc). Other frameworks relies on "actors", "commands", "brokers" and a lot of other complicated concepts, studio deals only with functions and promises, if you know both concepts you're ready to use and master it.
The main goal is to make all systems responsive, fault tolerant, scalable and maintainable. The development with Studio is (and always will be) as easy as possible, i'll keep a concise api, so other developers can create (and share) plugins for the framework.
The plugin system and the decoupled nature of it enables you to have real time metrics in your services , ZERO CONFIGURATION CLUSTERIZATION ON DISTRIBUTED MACHINES and other improvements for your services.
Studio isn't only a library, it's a framework. It's really important to learn how to program and not only what each method can do.
I would love to receive feedback.Let me know if you've used it. What worked and what is wrong. Contribute and spread the word.
Wants to learn more???? Click here to join our slack channel
Table of contents
- Install
- Intro
- Why
- Getting Started
- Examples
- Modules / namespacing
- Co / Generators and flow-control
- Proxy
- Es6 Class
- Plugins
- Filters
- Timeouts
- Realtime metrics
- Retry
- Clustering
- Pro tips
- From Zero To Hero
- Dependencies
- Build
- Test
- License
Install
To install execute:
npm install studio --save
Intro
We all want our systems to be responsive, scalable, fault tolerant, maintainable and for the last, but not least, easy and fun to develop. With this goals in mind i decided to build a micro-services framework for nodejs using and architecture freely inspired on actors model. I present you Studio
Studio makes easy to create code without ANY dependency between your services, so you can deploy all in a single machine or just easily change to each one in a different machine or anything in between. It also enables operations timeouts, zero-downtime reload, let-it-crash approach (stop to be afraid of exceptions, Studio handles it to you), plugins and makes it nearly impossible to falls in a callback hell. Supports any web framework (we have examples with express) and helps you with flow-control using bluebird.
Studio encourages you to use the best practices of nodejs, it helps you to write simple, clean and completely decoupled code. And makes it very easy and fun.
First of all, everything in a Studio-based application is a service.
So if you're used to build SOA or micro-services all your services (and possible layers, as DAOs for instance) are going to be declared as a STATELESS SINGLETON services. Services have an unique identifier and communicate (always) asynchronously through message passing. The benefits of this approach is that it is really easy to take just some of your services to different servers and make a better use of it. Also, your services have the free benefit of deep copying the parameters before the message is delivered (so one service can't mess with the objects of another service) increasing your code security.
And this is it... this is all you need to create reactive applications.
Why
Now you might be wondering why systems created with Studio can be called a reactive system. As stated by the reactive manifesto, reactive systems are those who follow 4 principles:
- Responsive :
Responsive systems focus on providing rapid and consistent response times, establishing reliable upper bounds so they deliver a consistent quality of service.
Using Studio you just add a thin layer over your functions without compromising the responsiveness while giving you the power to interact with your application in runtime as in aspect-oriented programming
- Resilient :
The system stays responsive in the face of failure. This applies not only to highly-available, mission critical systems any system that is not resilient will be unresponsive after a failure.
This is critical for thoses using nodejs, Studio enforces you to use the best practices to avoid your process or any of workers to crash. And as all your services are written with async flow in mind it also makes easy to add redundance
- Elastic :
The system stays responsive under varying workload.
This is critical for Studio. All service calls are async so you never release zalgo, also every service call receives a copy of the parameters so a service cant mess with other service code. And for the last but not least using Studio plugins you can have measures of your code in realtime as using the timer plugin you can check the time needed to execute every single service call in your application and you can even send it easily for a statsd/grafana metrics dashboard. So this way you have an application ready to scale horizontally and also with the metrics to help you to decide when to do this.
- Message driven :
Reactive Systems rely on asynchronous message-passing to establish a boundary between components that ensures loose coupling, isolation, location transparency, and provides the means to delegate errors as messages.
All service calls in Studio are async, even if youre doing some sync code, Studio will make it run async. Also all call goes through the Studio router which enforces a deep clone of the parameters for security reasons, and all services are COMPLETELY DECOUPLED and isolated from each other
So the main reason to use Studio is because it makes it to reason about your code and make it scalable as hell.
Getting Started
To create a service all you need to do is pass a NAMED function to studio
var Studio = require('studio');
Studio(function myFirstService(){
return 'Hello World';
});
To call a service all you need to do is pass the identifier of a service to studio (remember all service calls returns a promise)
var Studio = require('studio');
var myFirstServiceRef = Studio('myFirstService');
myFirstServiceRef().then(function(result){
console.log(result); //Prints Hello World
});
Your service can receive any number of arguments. And also, you can get a reference to a service even if it was not instantiated yet (you only need it when calling) as in:
var Studio = require('studio');
//Get the reference for a non initialized service works perfectly
var myServiceNotInstantiatedRef = Studio('myServiceNotInstantiated');
Studio(function myServiceNotInstantiated(name){
return 'Hello '+name;
});
myServiceNotInstantiatedRef('John Doe').then(function(result){
console.log(result); //Prints Hello John Doe
});
Is that simple to run over Studio. No boilerplate required.
Now the things can get more interesting if youre running on node >= 4 or using the flag --harmony-generators, because studio supports generators out-of-the-box if they are available as in:
var Studio = require('studio');
var myFirstServiceRef = Studio('myFirstService');
Studio(function myFirstService(){
return 'Hello World';
});
Studio(function * myFirstServiceWithGenerator(result){
var message = yield myFirstServiceRef();
console.log(message); // Prints Hello World
return message + ' with Generators';
});
var myFirstServiceWithGeneratorRef = Studio('myFirstServiceWithGenerator');
myFirstServiceWithGeneratorRef().then(function(result){
console.log(result); //Prints Hello World with Generators
});
You can yield Promises, Arrays of promises (for concurrency), Regular Objects or even Thunkable (node callbacks) you can see hthe examples in the generators session
Also if youre running on node >= 6 or using the flag and --harmony-proxies. You can access the services easier:
var Studio = require('studio');
//Get a referenc

