SOA you want to be Service-Oriented

Evolving into SOA

Do you wanna build a SOA? Okay, bye.
Now I'm going to talk fast for a minute.


Chatrooms for Classrooms

Monolithic Architecture

Monolithic Advantages

SOA

SOA Advantages

BREATH

Service #2

Everything is a service

Identify a need

Pick an API

Build a second service

TodaysMeet: built a streaming service (ekg)

Answer:

One repo or many? New hardware or alongside? Supervisor/forever/upstart. Fabric/grunt/gulp.
This is the hard part. I'll come back if there's time.
I use: same repo, diff dirs; separate VPSes; supervisor; Fabric.
// new-service.js
router.on("/filter",
  function(req, res) {
    res.writeHead(200);
    res.end("OK");
  }
);
server = http.createServer(router);
server.listen(3000);
Just this is enough. Return JSON if you are going to do that.
"router" is code I plan to open source but not very good.

Get it running

Talk to it

// main-app.js
if (testThisRequest) {
  hostpool.request(
    "/filter", {},
    function(err, res) {
      if (err) {
        statsd.incr("svc.err");
      } else {
        statsd.incr("svc.success");
      }
    }
  );
}
Fire off requests. Some kind of "host pool" is useful. I have code I plan to opensource but it's not very good.

Implement the feature

// new-service.js
router.on("/filter",
  function(req, res) {
    res.writeHead(200);
    var result = DOIT(req);
    var out = JSON.stringify(result);
    res.end(out);
  }
);
server = http.createServer(router);
server.listen(3000);
"DOIT" is an exercise to the reader.
Actually returning result, just don't use it yet.

Measure Everything

// new-service.js
setInterval(function() {
    var mem = process.memoryUsage();
    statsd.gauge('rss', mem.rss);
    statsd.gauge('heapTotal',
                 mem.heapTotal);
    statsd.gauge('heapUsed',
                 mem.heapUsed);
}, 5000);
I dump this snippet into almost every node process I build and use Diamond to put system stats into graphite.

Start using it

// main-app.js
// in handle(request, result) {
  var text = // ...
  if (testThisRequest) {
    hostpool.request(
      "/filter", {},
      function(err, res) {
        if (err) {
          statsd.incr("svc.err");
          result.write(text);
        } else {
          statsd.incr("svc.success");
          result.write(res.cleaned);
        }
      }
    );
  }
}
Actually using it! Now we dial it up toward 100%.
BREATH

1, 2, n

This is when we start cleaning up and solving some of the "gross"

Conventions

Start developing conventions, based on your likes and needs.
For me, every app has a top level dir, then a conf dir.
Create argument conventions, make it easy to use a single starter script.

Roles

Helps to break physical hosts from roles.
Any host with a given role runs all services associated with that role.
Use lots of roles. e.g. common, users, diamond, supervisor, nginx, dev
Sometimes by-hostname is just easier with dev environments.

The Tools

me@jamessocol.com

Thank you!