COBOL at 60: Business's Oldest Language Now Runs on a Serverless Platform

COBOL turned 60 this month, and while the language is frequently treated as a punchline by programmers who've never written a line of it, it still sits at the core of the global financial system. Thomson Reuters reported three years ago that COBOL is behind 43% of banking systems, 80% of in-person financial transactions, and 95% of ATM card usage, with hundreds of billions of lines still in production. The language recently returned to the news cycle when New Jersey put out a call for COBOL engineers to help with an overloaded unemployment system—a problem that prompted IBM to offer free online COBOL training.

The jokes about COBOL's verbosity and age are usually made by people who have never actually used it. Now they can. COBOL is officially a supported language for Cloudflare's serverless Workers platform, compiled down to WebAssembly and running on the edge network. A live "Hello, World!" example in COBOL is up at https://hello-world.cobol.workers.dev/.

Brief Historical Context

COBOL (Common Business Oriented Language) emerged in 1960 from a committee designing a language specifically for business applications, with a syntax intentionally verbose enough to be readable. The language drew partly on FLOW-MATIC, an early language by Grace Hopper. COBOL arrived between FORTRAN (1957), LISP and ALGOL (1958), with APL and BASIC following in 1962 and 1964 respectively. C didn't appear until 1972. The late 1950s and early 1960s were a ferment of language design, from both industry (FORTRAN, COBOL) and academia (LISP, ALGOL).

The compiled language translates easily to WebAssembly for Workers. GNUCobol, the free implementation formerly called OpenCOBOL, is a good starting point for experimentation. A sample program that sums the numbers 1 through 1000 can be compiled from a file called terminator.cob:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. ADD.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 IDX  PICTURE 9999.
       77 SUMX PICTURE 999999.
       77 X    PICTURE X.
       PROCEDURE DIVISION.
       BEGIN.
           ACCEPT X.
           MOVE ZERO TO IDX.
           MOVE ZERO TO SUMX.
           PERFORM ADD-PAR UNTIL IDX = 1001.
           DISPLAY SUMX.
           STOP RUN.
       ADD-PAR.
           COMPUTE SUMX = SUMX + IDX.
           ADD 1 TO IDX.

The cobc compiler can produce an executable directly, or it can emit intermediate C code with the flag -C:

$ cobc -C -o terminator.c -x terminator.cob

The resulting .c file then goes through the standard WebAssembly toolchain. A live version of this program, modified to respond over HTTP, runs at https://terminator.cobol.workers.dev/.

From Film to Function

The oddly-named terminator.cob has nothing to do with science fiction—or rather, it does. The sample is literally code that appears in The Terminator (1984). The famous displays of the HK-Aerial hunter-killer craft that skims through the film include a snippet of actual COBOL, copied from a May 1984 issue of "73 Magazine" to make the fictional Skynet displays look techie.

The code used in this project is documented in a Behind The Screens video, with the original source available via the Internet Archive. With the compilation step finished, this same vintage code—the sort that would appear on a robot's targeting computer—executes today across a serverless edge network in over 200 cities.

Compiling COBOL to WebAssembly

Several COBOL compilers exist, including proprietary ones; Cloudflare chose GnuCOBOL for its open source status. In principle, the pipeline is straightforward: GnuCOBOL emits C, and Emscripten turns C/C++ into WebAssembly. The hard part was fitting a COBOL runtime and its dependencies into the Worker's constraints on binary size and CPU time.

GnuCOBOL's runtime library, libcob, implements COBOL semantics using GMP (GNU Multiple Precision Arithmetic Library) for calculations. Compiling both plus the COBOL program into a single Worker binary produced something too large and too slow, hitting the platform's CPU execution limit. The team then trimmed it down:

  • GMP was replaced with an optimized WebAssembly port designed for JavaScript, cutting both binary size and instantiation time.
  • Support for local user configuration and other rarely used features was patched out of GnuCOBOL, which removed the need for an emulated file system and all its syscalls.
  • Linking with JavaScript for HTTP operations cut more bulk.

Typical resulting binaries stay relatively lean: about 230KB with optimization on for a Conway's Game of Life implementation.

Since WebAssembly still lacks tight integration with platform I/O, HTTP response generation remains written in JavaScript—a lane kept open by Emscripten imports that expose the functions to C, where COBOL can interoperate through its C linkage. A rock-paper-scissors game demonstrates the pattern, with full source in the cobol-worker repository.

Deploying Your Own COBOL Worker

The resulting toolchain is free and shared on GitHub for anyone: the build system lives in the cobaul repository, and a starter template makes deployment easy.

With wrangler (Cloudflare's Workers CLI) installed, generating a new project is a one-liner:

wrangler generate cobol-worker [https://github.com/cloudflare/cobol-worker-template](https://github.com/cloudflare/cobol-worker-template)

Follow the interactive prompts to link your Cloudflare account, then complete the deployment:

npm run deploy

At the end, the console displays the URL where your COBOL program runs.

Tribute by Simulation

The project also includes a COBOL implementation of Conway's Game of Life as a memorial to John Conway, who died shortly before this work was posted. The simulation accepts an HTTP POST with 30 parameters forming a 15x20 grid layout, reproducing the same configuration shown in the XKCD tribute to Conway.

To run your own simulation of cellular life in the language of business data processing, take a few steps: up a Cloudflare account and a workers.dev subdomain, install wrangler, then generate a COBOL Worker from the template.

wrangler generate cobol-worker https://github.com/cloudflare/cobol-worker-template

After customizing wrangler.toml for your account and setting a project name such as my-first-cobol, grab src/index.js and src/worker.cob from the game-of-life repository, replace the template's files with them, and execute npm run deploy. The final Worker will be reachable at https://my-first-cobol.my-cool-name.workers.dev/.

None of this would have worked without Google Sven Sauleau, who handled the porting work and the "PROCEDURE DIVISION" section of the original post, and Dane Knecht, who suggested the Game of Life tribute.