nearForm releases fuge for microservices
By Peter Elger

I’m delighted to announce the first release of fuge, nearForm’s open source generation and execution environment for microservice development on Node.js. fuge is open source under the MIT license. fuge-logo

fuge background

At nearForm we have developed a significant number of microservice-based systems. There are clear benefits to the microservice architectural style. Primarily, we are able to work with smaller units of code that are easier to reason about and test in isolation. Microservices also give us the ability to perform rapid, incremental deployments and deliver features faster.

So what’s not to like?

Well, as with all approaches to software development, there are a number of trade-offs to be made. One of the main trade-offs with microservices is the developer experience. This can be difficult because in order to run a copy of the system for local development, you have to run several processes instead of a single monolith. Current IDEs and tooling are oriented towards monolithic system development and don’t support the microservice paradigm well. There is even a name for this dilemma: ‘shell hell’.

Escaping shell hell

fuge blog post fig 1

Figure 1: Shell hell

There are several approaches to tackling shell hell. At nearForm, we have tried them all. For one, you can apply the ‘ostrich algorithm’. In other words, just develop services in isolation and maintain a central integration and staging system. This can work for a while. However, this model begins to break down as the number of developers increases.

Another approach is to use containers. For example, docker-compose allows you to run a bunch of service containers with a single command. The problem with this is that the development cycle time can be a little slow as a new container layer needs to be built for each change.

On several projects at nearForm, we have built custom scripts to spin up our microservices and this has worked well. However, we decided that we didn’t want to keep reinventing the wheel. And so, fuge was born.

fuge features

fuge provides two key pieces of functionality to help accelerate microservice development. Firstly, it acts as a code generator to produce system and service scaffolding. Secondly, it provides an execution environment for microservices.

Let’s look at each of these features in turn.

Code generation

Whilst each project has its own unique requirements, code scaffold generation can be a great way to start off on a good footing and can help to speed up development.

If you have ever used Ruby on Rails, Yeoman or similar code generation tools, you will appreciate how powerful code generation can be. fuge provides a similar scaffold generation capability for microservices. Let’s look at this in action.

First of all, install fuge with:

npm install -g fuge

Once fuge is installed, cd to a clean empty directory and run:

fuge generate apparatus/system

fuge asks a few questions and then generates a fully functional system for you comprising a front end and two microservices. Under the hood, fuge runs a set of Yeoman generators to construct the system for you. Let’s take a look at the generated code:

Figure 2: fuge code

Figure 2: fuge code

fuge generates a system complete with Docker files for each component. This means that you can take the system as it is and create containers immediately. fuge uses the docker-compose file syntax, so the generated system is compatible with docker-compose, swarm and associated tools and can also be run in development using fuge.

Execution environment

Aside from code generation, the key benefit of fuge is an execution environment for microservices through the fuge shell.

Figure 3: fuge shell

Figure 3: fuge shell

The fuge shell provides a number of features that help you to develop a microservice-based system. These features are as follows:

  • The ability to start and stop groups of services with a single command
  • A network proxy that bridges between microservice processes and Docker containers
  • A process watcher that restarts microservices as changes are made to the code
  • Log tailing and searching on a per-service basis

Spin ‘em up

Being able to manage service processes en masse is a huge boon to local development. Within the fuge shell, the command start all spins up all processes that are under management. fuge watches all processes under management for changes and restarts as required. This makes integration testing and debugging significantly simpler.

Mix it up

If you have worked with Docker during local development on Mac or Windows, you have experienced the friction of having to determine the Docker VM IP address and then having to code services to connect to infrastructural containers such as Mongo or Redis. fuge automatically provides a proxy layer to make this transparent to service processes. This increased transparency significantly reduces container friction.

Wrap it up

At nearForm, we are actively using fuge on a number of projects. So far, we find it a great asset in our microservice development arsenal. fuge is under active development and we intend to keep adding features to it to make our – and your – life easier. Coming up on the road map, we will be adding more service generators and live debugging capability to allow us to seamlessly connect to and debug running service processes.

If you are interested in using fuge on your next project or adding it to a current one, check out the GitHub repository for more detailed documentation and examples. As always, feel free to get in touch with us at nearForm.

Subscribe to our monthly newsletter!
join the discussion