Chapter 49: Deployment in C++
Docker, systemd, Vercel, production checklist. In this chapter, you will learn deployment in depth with C++ code examples, explanations, and best practices.
Overview
This chapter covers deployment for Kungfu.js developers using C++. We will start with the basics, move through practical examples, and end with advanced techniques and common pitfalls.
Why This Matters
Understanding deployment is essential because it is a core part of building web applications. Every real-world app needs to handle docker, systemd, vercel, production checklist. Skipping this chapter would leave a gap in your knowledge that would cause problems later.
Code Example
Here is how to handle this in C++:
# Build for production
cargo build --release --features "kungfu-core/io_uring kungfu-core/simd"
# Dockerfile
FROM rust:1.96 AS builder
WORKDIR /app
COPY . .
RUN cargo build --release
FROM debian:bookworm-slim
COPY --from=builder /app/target/release/myapp /usr/local/bin/
EXPOSE 3000
CMD ["myapp"]
Deployment Checklist
- Build with
--releaseflag for optimizations - Enable io_uring and SIMD features on Linux
- Set
acceptor_threadsto the number of CPU cores - Put behind a reverse proxy (nginx/Caddy) for TLS
- Increase file descriptor limit:
ulimit -n 1048576 - Set up health checks at
/health - Configure graceful shutdown
Common Mistakes
- Not reading the documentation: Always check the API reference when something does not work as expected.
- Skipping security: Never disable the default middleware unless you have a very good reason. Security is not optional.
- Not testing: Write tests for your handlers. Kungfu.js makes this easy with the built-in test utilities.
Summary
In this chapter, you learned about deployment in C++. You saw code examples, understood how things work under the hood, and learned about common mistakes to avoid.
What is Next?
In chapter 50, we will cover Build a Full-Stack App: Put it all together: a complete project.