Realtime Doesn’t Belong Everywhere — Build Scalable API Services in Node.js with Nodal

Keith Horwood
The RESTful Web
Published in
4 min readMar 8, 2016

The push to develop realtime web apps has been a fun one, and we’ve seen some awesome products come out of it. Websockets as a technology are great. And there are a ton of tools that let you prototype impressive realtime apps in a flash. Unfortunately, these come with their own host of problems. Stateful socket connections can be messy, and as you build an app with the intention of scaling sometimes realtime just doesn’t quite fit. It can create more problems than it solves as you begin hitting edge cases or need to build a system without as much tight coupling. You thought you had a magic bullet solution, but you need something a little bit different. Where do you turn?

The architectural pattern we have for building scalable web applications is time-tested and clear. Distributed, stateless API services that allow any web, mobile or IoT app to interface with a protected data layer — in many cases, just a database. As web projects grow in size and the number of clients that consume your API data increase (tablets, watches, TVs, you name it) it’s becoming increasingly important to look at web development through the lens of service-oriented architecture for every layer — and begin pulling your API logic apart from your client-side presentation completely.

Nodal — Your API Solution

This is where Nodal comes in. Nodal is a Node.js framework for building API services. We’ve packaged Nodal with full PostgreSQL and migration support. We’re already including GraphQL support for your next React project. There’s a lot more, but when it comes down to it what we’re going to do is save you a lot of time.

With our most recent release, Nodal 0.8, we’re solely focused on being the best way to develop API services, period. To those who have been following Nodal over the last couple of months — thank you! Your continued support has been phenomenal. I’m humbled so many people love what we’re building.

There are three reasons you should consider using Nodal for your next project. First, we encourage simplicity and readability for development. Secondly, we save time by making decisions for you. Finally, we set up the foundation for a scalable architecture by encouraging developers to think in terms of building distributed systems for multiple clients.

Simplicity and Readability

Nodal’s focus is on communicating with the developer. Everything from our core modules to the way you’ll write API endpoints have all been crafted with you and your team in mind. The simplest explanation for what’s happening is exactly what’s going on behind the scenes. The call stack is easy to trace. You won’t get lost in confusing abstractions. If you’re coming from another MVC framework, the transition should feel relatively seamless. There will be a lot of things you’ve seen before, and the things you haven’t are easy to grok.

Here’s an example Controller for an HTTP endpoint for blog posts:

Time-Saving by Decision Making

As an opinionated framework, Nodal makes a lot of decisions for you. Don’t worry about where to put files, which ORM to use, or how to deploy. Nodal comes with a host of goodies designed to save your most important resource — time. With a pre-defined directory structure, common design patterns for writing modules, CLI tools that write a lot of code for you, built-in PostgreSQL integration, and production deployment capabilities ready to go Nodal is going to build your next API in minutes.

Foundation For A Scalable Architecture

Nodal is stateless by design. What I mean by that is that the server instance itself is designed to be able to spread request load across multiple processes without any additional configuration, and there is no shared memory between processes without communicating with an external service like your database. These processes have low spin-up time if any instances crash or are unavailable. This encourages thinking about development in the context of distributed services by design, instead of as an afterthought.

Let’s Build

“Great,” you begin, “you have my interest. Where do I start?”

There’s an awesome tutorial available to get you started for version 0.7, but it’s still relevant for Nodal 0.8. You could also begin getting a foothold with some older screencasts. Most of Nodal’s foundation is beginning to solidify so I wouldn’t worry too much about breaking API changes from this point forward. We’re getting pretty close to developmental stability. If you have any trouble, just ask for clarification. I’m on Twitter, @keithwhor.

The project is being worked on tirelessly by yours truly, and our community Gitter channel is pretty active whenever somebody needs help, so join in!

Finally, I want to once again give thanks to the current community and those willing to give Nodal a shot. It feels great to build something that helps push development forward and make everything just a little bit easier. To keep up to date with Nodal announcements please check out Nodal on GitHub and follow me on Twitter, @keithwhor.

--

--