I've inherited a pretty interesting project where there is a good opportunity to take an existing piece of software and turn it into a SaaS web app. As the project is inherited, the code base/ framework is already defined as C++ and MySQL. The app itself is compiled and run as an EXE on Windows Server. The UI is web based and the app works as a kind of server. From what I do know of modern web apps, this is perhaps an unusual choice. These days, most people seem to opt for a PHP framework or Ruby on Rails. Certainly that is the impression I get from reading blogs on the subject. So, I'm very interested to know if a C++ EXE backed by MySQL is a solid foundation for a web app, or whether we should be looking to build in another way?

  • What you describe sounds more like a server process and not a webapp. And for server processes PHP or RoR are certainly unusual choices. What kind of problem do actually you have? Commented Sep 7, 2012 at 13:57
  • Does the exe perhaps use the new Hostable Web Core ( awesomeideas.net/page/IIS7-Hostable-WebCore.aspx ) or does it actually implement it's own HTTP server from scratch? If the former, then perhaps they were really trying to make a very fast app by using C++ and self-hosting it for portability to client machines.. Commented Sep 7, 2012 at 14:20
  • Of course anybody sane would use something like POCO's Net::HTTPServer instead of writing a HTTP server from scratch. But it is not like RoR or e.g. Python frameworks don't pack some webserver. Commented Sep 7, 2012 at 14:36
  • 4
    It's not that unusual to have c++ as the backend of a web application. Google search is written in c++. Many of yahoo's apps are c++. Pretty much every AAA web app used by millions of people is written in c++.
    – Lord Tydus
    Commented Sep 8, 2012 at 23:05
  • Yes, the app was designed as a custom web server. So the web app side of it comes from the HTML admin UI and feature set.
    – jnthnclrk
    Commented Sep 9, 2012 at 15:41

4 Answers 4


It is OK to make a web application using C++ IF the benefits outweighs the cost, obviously. Google, Amazon, Facebook are all built with C++ for efficiency in speed, memory and energy - aka servers costs.

However as you guessed, there are drawbacks to using C++ for this. It depends on your tools though.

First let me cite cppcms website on this:

When CppCMS Should Be Used.

C++ language is far from being popular for Web development for many reasons: lack of appropriate tools, skills of developers and many more.

However, there are areas where C++ web programming with CppCMS becomes very useful and efficient, and some where it is just a waste of time.

When CppCMS should or can be used?

1.High load web sites and application with hundreds and thousands hits per second, where high performance, efficiency and scalability is required.

2.Application that require scalable Comet/Server Push technologies --- CppCMS can efficiently handle hundreds and thousands simultaneous HTTP connection with minimal resources usage.

3.Embedding web interface into existing C++ applications/services with a small cost of additional library.

4.Embedded underpowered devices -- CppCMS allows creation of rich applications with relatively low cost of hardware that would perform reasonably fast.

When Not To Use?

If you create small web applications that do not require high loads and require very short time-to-market period -- probably tools like Django or RoR would be more appropriate for such tasks.

The drawbacks specific to C++ are:

  • Compile times can be very very very very slow compared to other languages. This might impact iterations, release interval but also developer's moral. Make sure it's worth it.
  • Most of the time, you need to compile changes. It can be avoided but it's the usual.
  • Writing modern C++ makes it easy (to learn, read, write, debug, etc.), but a lot of C++ developers don't know what is Modern C++. So if you work in team, you need to have good knowledge of Modern C++ from the whole team. If not, you will easily get into very complicated bugs. That said, it's more a people problem than a language problem. It's just that C++ history didn't help make it easy to grasp. Good teaching is not as common as in more modern (historically) languages.
  • Unicode is still poorly supported by the core C++ language, making it a potential source of great pain. Just use UTF-8 everywhere and some libraries (look into boost) to manage it.
  • C++ standard don't know what is a library. So we use conventional ways to manage them on different compiler/linker/OS. This might be a problem if you start to get into cross-platform code that need to load/unload "on the fly" some modules.

Maybe take a look at CPPCMS? Or maybe wt if you want to make a GUI-style website?

Also check these questions:

  • 3
    My understanding is that Facebook is programmed in PHP, but they also built their own native compiler for PHP in C++ for Linux. The main reasons Facebook developed the compiler was to reduce their electrical costs for operating servers. It wasn't really speed (it is faster) but the fact that it requires less CPU usage per request. It's an open source project that can be found here. developers.facebook.com/blog/post/2010/02/02/…
    – Reactgular
    Commented Sep 7, 2012 at 15:21
  • 1
    Yes, reasons varies, that's why I mentioned energy and servers cost. That being said, Alexandrescu said recently in an interview, I believe, that more and more of Facebook code is written directly in C++, but he didn't mention why, if my memory is correct. They also provide an open source library full of C++ utility/algorithms: Folly facebook.com/notes/facebook-engineering/…
    – Klaim
    Commented Sep 7, 2012 at 15:26
  • Also note that even if the code is first written in PHP first then converted to C++, 3 of the drawbacks I pointed are still true.
    – Klaim
    Commented Sep 7, 2012 at 15:28
  • 2
    Another C++ web framework: wt (witty). It's for people who want to build web apps that work like desktop apps under the hood. For porting, it's a good choice.
    – K.Steff
    Commented Sep 7, 2012 at 15:39
  • I think all of those sites have components written in multiple languages. C++ is most likely used as an optimization for sections of code that require fine-tuned memory management.
    – jiggy
    Commented Sep 7, 2012 at 19:53

Wordpress running in PHP with a few plugins installed brings my Winders server to it's knees. So I have no problems at all with the idea of implementing a web application in C++. Speed is a critical part of the web experience.

Graphic design tents to drive the majority of web projects. PHP is an obscure scripting language that runs inside HTML. Allowing the PHP authors to escape in and out of HTML. There are many benefits with working with HTML as a result.

Still, you could implement any number of HTML template solutions in C++.

One could provide you with an long list of Python and PHP frameworks that make for rapid development, but if you have lots of time then C++ is definitely possible.

What I don't understand is your decision to do C++ on Windows. lol

  • 1
    Classic straw man argument, there are many better fast alternatives to wordpress/php that aren't C++. I'm not saying C++ isn't a relevant choice, just your argument is not really framed very well. Commented Sep 7, 2012 at 16:52
  • I agree with you. I don't think I was trying to make wordpress an alternative. It's just that my experience has been lately as shown it's difficult to get good performance out of popular frameworks.
    – Reactgular
    Commented Sep 7, 2012 at 18:50
  • 1
    StackExchange runs on ASP.NET MVC framework. Node.Js is low weight high performance and if you really want something ridiculously performant there's Snap or Yesod Haskell frameworks yesodweb.com/blog/2011/03/…, Haskell, JavaScript, and C# all being high level garbage collected languages. Commented Sep 7, 2012 at 18:55
  • 1
    Mind that Code execution speed on the server in many cases is not the limiting factor in a web app. Big parts of the time is spent waiting for something (database) or even in the front end (fetching CSS, images, doing JavaScript things, HTML rendering)
    – johannes
    Commented Sep 8, 2012 at 22:58

It certainly is an unusual choice. C++ wasn't designed with web applications in mind, and while libraries exist to write, say, FastCGI applications with C++, you have to do a lot more work to get your basic application up. "Web languages" usually do a lot of things for you that you have to get from elsewhere in C++, such as implementing the HTTP protocol, generating HTML, etc.

Also, web applications are mostly about strings, which isn't exactly C++'s strongest side - there is no string type built into the language itself, and this leads to a few quirks and makes string processing more clumsy than it would be in more high-level languages. Handling character encodings correctly in C++ borders on black magic. And C++ can crash really hard, on fairly innocent-looking code, which is far less likely with a higher-level language (they too can crash, but in most cases, the web server can recover gracefully, especially on platforms that use a per-request lifecycle model, like PHP).

That said, if you have most of the codebase written already, C++ might still be a viable choice. You will need to find some libraries to cover all sorts of web things (most notably, you want to be able to either integrate a standalone HTTP web server into your program, or hook into, say, Apache, either through FastCGI or by compiling to a module; you will also want some kind of templating library to make rendering HTML documents painless).

Finally, there's the developer market issue. There are plenty of C++ developers available, and even more web developers, but the overlap is probably not that large, so if you ever need to hire people to work on this thing, you'll have a somewhat harder time than with, say, PHP.


As others have said, conceptually, C++ is a fine environment for a web server development. There are however, several considerations as you make that decision.

The popularity of scripting languages for web server design is turn around time. Simple changes can be made easily with the demonstration of results nearly immediate. You will find that any good web server design will offer similar capabilities. Indeed, C++ is an excellent environment for achieving that goal.

The key to building a good web server application system is a separation of UI from code. A goal in building a web application environment is to avoid "Your UI is in my code and your code is in my UI."

I would like carefully at systems like cppcms. I would expect that it offers something similar.

You don't need a scripting language to offer flexibility and performance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.