Nyx con Ejemplos

Stack de Producción

El stack de producción completo de Nyx que da vida a nyxlang.com. El gateway termina TLS y enruta según el header Host hacia instancias de nyx-serve por dominio. Los servicios compartidos (nyx-kv, nyx-queue, nyx-db) proveen estado. Sin nginx, sin Redis, sin Postgres — solo binarios de Nyx y systemd.

Código

// 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
}

Salida

=== 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).

Explicación

Esta no es una arquitectura hipotética — es la forma en que nyxlang.com efectivamente corre en este momento. Un único binario nyx-proxy en el puerto 443 termina TLS con SNI y despacha según el header Host hacia cuatro sitios independientes de nyx-serve, cada uno un binario compilado desde Nyx con nyx-serve como dependencia PM. nyx-kv guarda sesiones y cachés; nyx-queue maneja trabajos asíncronos; nyx-db almacena SQL durable. Cada proceso es una unidad de systemd con una política de reinicio. Todo el stack — gateway, cuatro sitios, tres servicios, playground — cabe en 1GB de RAM en un t4g.micro, y la única dependencia que no es Nyx es certbot para las renovaciones de Let's Encrypt. Ese es el final del cookbook: ahora tienes todos los primitivos necesarios para construir y desplegar servicios de producción en Nyx.

← Anterior Todas las recetas →

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