Nyx by Example

Production Stack

The complete Nyx production stack powering nyxlang.com. Gateway terminates TLS and routes by Host header to per-domain nyx-serve instances. Shared services (nyx-kv, nyx-queue, nyx-db) provide state. No nginx, no Redis, no Postgres — just Nyx binaries and systemd.

Code

// Production deployment — full Nyx stack: proxy + web + kv + queue

fn main() -> int {
    // This recipe describes how nyxlang.com is deployed end-to-end
    // using only Nyx products. No nginx, no Redis, no Postgres.

    print("=== Nyx Production Stack ===")
    print("")
    print("Internet")
    print("   |")
    print("   v")
    print("nyx-proxy (services/gateway, :443 HTTPS + SNI)")
    print("   |")
    print("   +-> nyxlang.com       -> nyx-serve (:3001)")
    print("   +-> nyxkv.com         -> nyx-serve (:3002)")
    print("   +-> serve.nyxlang.com -> nyx-serve (:3003)")
    print("   +-> proxy.nyxlang.com -> nyx-serve (:3005)")
    print("")
    print("Each site is a Nyx binary using nyx-serve as PM dependency.")
    print("")
    print("Shared services:")
    print("   nyx-kv   :6380  (sessions, cache, pub/sub)")
    print("   nyx-queue:6381  (async jobs)")
    print("   nyx-db   :6382  (SQL storage)")
    print("")
    print("All managed by systemd. HTTPS via Let's Encrypt + cert-renew hooks.")
    print("")
    print("Performance (production):")
    print("   HTTP:  9,971 req/s through gateway")
    print("   HTTPS: 4,282 req/s (TLS overhead)")
    print("   KV SET: 82K req/s (253K pipelined)")
    print("   KV GET: 85K req/s (217K pipelined)")
    print("")
    print("Entire stack fits in AWS t4g.micro ARM64 (1GB RAM).")
    return 0
}

Output

=== Nyx Production Stack ===

Internet
   |
   v
nyx-proxy (services/gateway, :443 HTTPS + SNI)
   |
   +-> nyxlang.com       -> nyx-serve (:3001)
   +-> nyxkv.com         -> nyx-serve (:3002)
   +-> serve.nyxlang.com -> nyx-serve (:3003)
   +-> proxy.nyxlang.com -> nyx-serve (:3005)

Each site is a Nyx binary using nyx-serve as PM dependency.

Shared services:
   nyx-kv   :6380  (sessions, cache, pub/sub)
   nyx-queue:6381  (async jobs)
   nyx-db   :6382  (SQL storage)

All managed by systemd. HTTPS via Let's Encrypt + cert-renew hooks.

Performance (production):
   HTTP:  9,971 req/s through gateway
   HTTPS: 4,282 req/s (TLS overhead)
   KV SET: 82K req/s (253K pipelined)
   KV GET: 85K req/s (217K pipelined)

Entire stack fits in AWS t4g.micro ARM64 (1GB RAM).

Explanation

This is not a hypothetical architecture — it is how nyxlang.com actually runs right now. A single nyx-proxy binary on port 443 terminates TLS with SNI and dispatches by Host header to four independent nyx-serve sites, each a binary compiled from Nyx with nyx-serve as a PM dependency. nyx-kv holds sessions and caches; nyx-queue handles async jobs; nyx-db stores durable SQL. Every process is a systemd unit with a restart policy. The whole stack — gateway, four sites, three services, playground — fits in 1GB of RAM on a t4g.micro, and the only non-Nyx dependency is certbot for Let's Encrypt renewals. That's the end of the cookbook: you now have every primitive needed to build and ship production services in Nyx.

← Previous All recipes →

Source: examples/by-example/100-production-stack.nx