MCPSERV.CLUB
Varnish

Varnish

Self-Hosted

High-performance HTTP reverse proxy and caching

Active(100)
4.0kstars
0views
Updated 9 days ago

Overview

Discover what makes Varnish powerful

Varnish is a high‑performance HTTP reverse proxy and caching engine written in C. It sits between web clients and origin servers, intercepting requests to serve cached content, reduce latency, and offload backend load. Developers use Varnish when they need to accelerate dynamic sites, implement sophisticated cache strategies, or expose a programmable interface for traffic shaping and content manipulation.

Request/Response Manipulation

Fine‑grained Cache Policies

High Concurrency

Statistical Exposure

Overview

Varnish is a high‑performance HTTP reverse proxy and caching engine written in C. It sits between web clients and origin servers, intercepting requests to serve cached content, reduce latency, and offload backend load. Developers use Varnish when they need to accelerate dynamic sites, implement sophisticated cache strategies, or expose a programmable interface for traffic shaping and content manipulation.

Key Features

  • Request/Response Manipulation: Varnish Configuration Language (VCL) allows developers to write logic that runs at different request stages (vcl_recv, vcl_backend_response, vcl_deliver). VCL can modify headers, rewrite URLs, or decide whether to fetch from cache.
  • Fine‑grained Cache Policies: Time‑to‑live (TTL), grace periods, and stale‑while-revalidate can be defined per object. Developers can implement custom hashing, hit/miss logging, and cache invalidation via the ban API.
  • High Concurrency: Varnish uses a multithreaded, event‑driven architecture with minimal locking, enabling millions of requests per second on commodity hardware.
  • Statistical Exposure: Built‑in stat and debug tools expose counters, latency histograms, and object statistics over a RESTful interface (e.g., curl http://localhost:6082/varnishstat).

Technical Stack

  • Language & Runtime: C (core engine), Lua (optional embedded scripting), and a VCL compiler that translates VCL to C at load time.
  • Networking: Epoll (Linux), kqueue (BSD/macOS) for scalable I/O; built‑in TCP keepalive and connection pooling.
  • Storage: In‑memory LRU cache with configurable memory usage; optional disk persistence via storage.file for large objects.
  • APIs: Varnish Administration Interface (VAPI) over TCP, providing ban, purge, and reset commands; RESTful JSON endpoints for metrics.

Architecture

Varnish follows a classic proxy architecture:

Client → Varnish (frontend) → Origin Server (backend)

The frontend listens on port 80/443, while the backend pool is defined in VCL. Internally, Varnish maintains a cache object store and an object queue for pending fetches. The vcl_recv hook processes incoming requests, deciding whether to serve from cache or forward to a backend. Once a backend response arrives, vcl_backend_response can transform it before storing it in the cache. Finally, vcl_deliver runs just before the response is sent to the client.

Deployment & Infrastructure

  • Self‑Hosting: Requires a Linux/Unix host with at least 1 GB RAM for modest workloads; larger deployments scale linearly with memory. Varnish can run inside Docker containers, Kubernetes pods, or as a systemd service.
  • Scalability: Horizontal scaling is achieved via load balancers distributing client traffic across multiple Varnish instances. Each instance operates independently, sharing a common cache backend if needed (e.g., via storage.file or external shared memory).
  • High Availability: Combined with HAProxy or NGINX, Varnish can be placed behind a failover layer. The stat endpoint enables health checks, and the graceful shutdown API (varnishadm stop) ensures no requests are dropped.

Integration & Extensibility

  • Plugin System: Developers can write C plugins to extend core functionality (e.g., custom hashing, authentication). The plugin API is well‑documented and stable across releases.
  • Webhooks & Callbacks: VCL can trigger external scripts using call statements, enabling integration with CI/CD pipelines or monitoring tools.
  • REST APIs: The VAPI and varnishstat JSON endpoints expose operational data for dashboards (Grafana, Prometheus) or custom tooling.

Developer Experience

  • Configuration: VCL is declarative and concise; most developers can learn it in a day. The compiler provides detailed error messages, making debugging straightforward.
  • Documentation: Official docs are comprehensive, with reference manuals for every VCL function and API. Community-contributed tutorials cover common patterns (cache purging, TLS termination).
  • Community & Support: A vibrant mailing list and IRC channel exist. The project maintains a public issue tracker, encouraging rapid bug fixes and feature requests.

Use Cases

  • Dynamic Site Acceleration: Cache generated HTML or API responses for a few minutes to reduce database load.
  • API Gateways: Throttle, authenticate, and cache API calls before reaching microservices.
  • Edge Caching: Deploy Varnish at the edge of a CDN to offload origin servers.
  • Testing & Development: Use Varnish’s ban API to simulate cache expiry in integration tests.

Advantages

  • Performance: Varnish consistently outperforms generic reverse proxies in throughput and latency due to its event‑driven, low‑overhead design.
  • Flexibility: VCL provides granular control over caching behavior, enabling custom business logic without code changes in backend services.
  • Licensing: BSD‑licensed, allowing unrestricted use in commercial and open‑source projects.
  • Ecosystem: Mature tooling (e.g., varnishadm, varnishstat) and integration with monitoring stacks make it a turnkey solution for high‑traffic

Open SourceReady to get started?

Join the community and start self-hosting Varnish today

Weekly Views

Loading...
Support Us
Most Popular

Infrastructure Supporter

$5/month

Keep our servers running and help us maintain the best directory for developers

Repository Health

Loading health data...

Information

Category
cloud-platforms
License
NOASSERTION
Stars
4.0k
Technical Specs
Pricing
Open Source
Database
None
Docker
Community
Supported OS
LinuxDocker
Author
varnishcache
varnishcache
Last Updated
9 days ago