loading...
Cover image for Modern cloud-native C++ microservice. Part 1 — Intro

Modern cloud-native C++ microservice. Part 1 — Intro

andreybronin profile image Andrey Bronin ・3 min read

More then year have passed since I joined the Insolar team and switched from C++ to Golang. C++ was my main programming language for more than 10 years. Here in Insolar we are developing a blockchain platform for businesses.

I know couple companies are migrating their huge codebase from C/C++ to modern languages like Go and Rust. They also are splitting monolith to microservices.

I decided to improve my skills in software architecture, product management and leadership, and I started an open source project. I found several remote programmers and formed a development team. People wanted to get experience and public portfolio, but all of them used different languages. I decided to use microservices because of that.

One guy wanted to use C++ and I asked him to search for good examples of Cpp cloud-native microservice, but he didn’t find any. Then I were googling for several days but didn’t find too. I’ll try to write my own.

C++ is not popular for web development, but modern C++17 and C++20 standards are pretty cool and useful.

GCC 9.1 was released and now it one step closer for support of the new standard.

Why programmers have to rewrite their code to a different language? They could take familiar but modern tools. What do you think?

I also have experience in Java, Ruby, JS, PHP on the backend. And I’ll try to bring the best practices from different worlds.

C++ is not popular for cloud apps because of several reasons.

  • the language is complex, memory management

  • the standard library doesn’t provide networking features

  • dependency and third-party management

  • complex building system, linking and potential ABI issues

  • holy wars about code style

  • tooling, code coverage, linters, code checkers are hard to setup

Let’s talk about this reasons.

Language complexity

I agree, the language is complex with manual memory management, but it follows the zero-overhead principle.

“What you don’t use, you don’t pay for”

The language also has C++ Core Guidelines which follows “subset of superset” principle. It means you should use simple and safe language subset in most cases.

A memory leak is a very bad thing, especially in a monolithic architecture. But today you have tools to solve this problem. First, are developer tools such as profiling and code sanitizers.

Standard library

C++ was released in 1985 and still doesn’t provide networking features in standard library, but we have Boost, POCO, Qt and several modern network libraries e. g. Pistache, restbed, evpp.

Dependency management

If you take any modern language, it has package manager. In c++ world people uses several approaches: operating system package managers(apt, yum, homebrew), git submodules and own bicycle scripts written on python, perl, bash, etc. There are also several special package managers: Conan, Hunter, Buckaroo, cpm, qpm.

I think Conan is best and production ready solution for cpp package management. I chose it for my example. Conan has two big repos: oficial conan-center and community bincrafters.

Build system

There are several build systems in C++ world, but CMake became standard de-facto. CMake recipes are not easy to read and understand, but if you look to WebPack or Gradle, you will agree that it complex too. Developers should well study ecosystem tools.

Coding style and culture

Some languages have a default community accepted coding style: Python PEP-8, PHP PSR-2, but C++ doesn’t. All teams, where I worked, had own coding style usually based on Google C++ Style Guide . Now I’m happy that Golang developers use built-in formatting tool and don’t argue about CamelCase, Egyptian brackets etc.

It doesn’t matter which language developers use, they should follow good practices: code review, unit testing, automated code analysis. There are many tools for that, see below.

Tooling

You should choose tools and set up your own CI pipeline. Some good tools are paid.

  • Clang and GCC sanitizers

  • code coverage: lcov, BullsEye, CoCo

  • Static code analyzers: cppcheck, clang-tidy, pvs-studio

Future articles

  • Cloud native C++ microservice. Part 3 — Dependencies, Package Managers, Conan.io

  • Cloud native C++ microservice. Part 4 — Observability

  • Cloud native C++ microservice. Part 5 — Databases

  • Cloud native C++ microservice. Part 6 — Auth, JWT

  • Cloud native C++ microservice. Part 7 — API, REST,GRPC

Discussion

pic
Editor guide