Hacker News new | ask | show | jobs
by powersurge360 1419 days ago
I'm very surprised that C++ is one of the recommended languages for backend services. I occasionally am interested in learning C++ but with my context as a web developer I find it doesn't really fit any of my use cases.

How would one go about building a rest service in C++? Do you have to write everything yourself or are there libraries and frameworks. I did some light looking into it after reading the article but I would love to hear from folks who actually do it and what the state of the art is for C++ web services.

9 comments

There are libraries and frameworks.

Note that before Java adoption push we had stuff like ATLServer, and the first version of ASP were basically COM libraries being called from VBscript/JScript.

On our case, we were calling C code from TCL scripts, using plugins like mod_tcl.

Nowadays you have stuff like Boost ASIO and Wt.

However I wouldn't plug C or C++ directly into the Internet, rather call them from managed languages, as native libraries, reducing the risk of possible exploits.

This is what I had considered to be the state of things. The phrasing on initial read suggested to me that C++ & Rust were the default now for performance critical services (with Rust being a new add) and Hack was used where it made sense but not necessarily by default anymore. I think I may have discounted Hack's role too much.
Clearly one can write web services in C++. Meta does not really, though. It is Hack code that talks to most web clients (and python for Instagram). The C++ code sits behind that. All of the databases, the caches, the indexing services, the ads ranking and selection are written in C++ and talk Thrift to each other and to the Hack code.
> How would one go about building a rest service in C++?

I'd use https://github.com/drogonframework/drogon if the app needs to be pure C++ or Cutelyst (https://cutelyst.org/) if it's a Qt app which needs to expose an http server

I haven't built anything serious with it, but cpp-httplib is a very easy-to-use framework for processing HTTP requests.
"backend" does not necessarily means the part that receives the HTTP request from the client. It could be a microservice that speaks some other protocol, a load-balancer that sits in front of the web workers, and task runner, etc.
> How would one go about building a rest [service.]

At Meta, you wouldn't. Everything is Thrift. For WWW, you'll have more graphql.

Meta also has a shit ton of libs to make service development easier than exists publicly.

If you have organizational backing, it is not hard to use C++ because the company would have already standardized on libraries like Boost and Folley.

And the company would already have a build farm.

I’d bet they use e.g. Python to receive the HTTP calls and do basic logic at that level, but use C++ libs to chew through lots of multimedia, ML/AI, etc.
Check out WebAssembly.