Writing Docker Microservices in COBOL

Most developers think of COBOL as a dead language. Surprisingly, the TIOBE Index for October 2016 lists COBOL as the 24th most popular language, between Dart and Scratch. Developed in 1959 before most of today’s developers were born ( including me ), seen by many as “uncool”.
There is one thing that COBOL does very well and that has kept around longer than one would expect. The one thing that COBOL does well is volume processing. A lot of very big companies and firms use it to process a lot of data. The Social Security Administration currently has about 60 million lines of COBOL in production, and the US Navy and the Internal Revenue Service still use COBOL.
What happens when we need to access COBOL programs in a more modern architecture? What happens we we have to move a function that has been performed by a COBOL program in house for years?
A lot of programmers when faced with integrating COBOL with their new program, want to take the “chuck the whole lot out the window approach” and re-write from scratch. Not only can this be expensive, it can create more problems because of the business process rules that have been built into the code over the years.
What we can do is take those mature business processes that have been around for years and wrap them in a microservices architecture to migrate your old code to a new architecture. Using a Docker container, I will show you how to wrap a COBOL program in a microservice.

Docker makes running apps in different languages incredibly easy. Using Docker, you can have a NodeJS application running with a PHP app and even a COBOL application all connected in a microservice architecture.
Since most versions of COBOL in use do not have much support for internet connectivity, we use a wrapper in a web-friendly language to handle the input and output from the COBOL code.
There are a few ways to do this including , quite suprisingly, a NodeJS to COBOL bridge which allows you to run COBOL code from NodeJS. ( https://github.com/IonicaBizau/node-cobol ) Some modern flavors of COBOL have support for microservices baked in.
We are not trying to write new COBOL to replace old COBOL with this example. We are trying to bridge the COBOL code that we currently have with a microservice.
In this example, I wrote the microservices wrapper to a COBOL program in PHP. You could, of course, write a wrapper in any language or framework. The PHP bridge should handle all the normal error handling and signals that are expected from a microservice. The example is a simple COBOL “hello world” program that I would like to make into a simple microservice to return a JSON string.

First, a simple “hello world” COBOL example. The code simply returns a JSON response
IDENTIFICATION DIVISION.PROGRAM-ID. JSONTest.DATA DIVISION.PROCEDURE DIVISION.DisplayPrompt. DISPLAY ‘{ ok:1, text: “Hello,World”}’. STOP RUN.
To call the COBOL “hello world” app you can use curl to call the microservice.
curl -H “Content-Type: application/json” http://127.0.0.1:7707
If you can run docker, I have a docker image gregcoleman/cobol-microservice-example on docker hub or you can pull the source from Github https://github.com/gregorycoleman/cobol-microservice-example.
This is just a demonstration app and it should not be used as the basis for any production development. A proper wrapper would have more input checking, signal handling, and error handling.
Was this post interesting? If so, please click the ❤ below to let me know , it really does help. Greg Coleman is a freelance devop based in Annapolis, Maryland that is planning a trip to an undisclosed location somewhere in the South East Asia looking for the perfect Unagi roll. You can contact me here https://gregorycoleman.github.io