# Finagle — Extensible RPC System for the JVM > A protocol-agnostic RPC framework from Twitter built on Netty. Finagle provides connection pooling, load balancing, retries, and distributed tracing for building resilient microservices on the JVM. ## Install Save as a script file and run: # Finagle — Extensible RPC System for the JVM ## Quick Use ```scala // build.sbt libraryDependencies += "com.twitter" %% "finagle-http" % "24.2.0" ``` ```scala import com.twitter.finagle.Http import com.twitter.finagle.http.{Request, Response, Status} import com.twitter.util.{Await, Future} val service = (req: Request) => { val rep = Response(req.version, Status.Ok) rep.contentString = "Hello from Finagle" Future.value(rep) } val server = Http.serve(":8080", service) Await.ready(server) ``` ## Introduction Finagle is a JVM-based RPC framework developed by Twitter (now X) for building high-throughput, fault-tolerant distributed systems. It abstracts transport details behind a uniform client-server API and provides built-in observability, load balancing, and failure management. ## What Finagle Does - Provides protocol-agnostic client and server building blocks for HTTP, Thrift, gRPC, MySQL, and more - Implements client-side load balancing with pluggable strategies (round-robin, least-loaded, aperture) - Handles retries, timeouts, circuit breaking, and rate limiting out of the box - Integrates with Zipkin for distributed tracing across service boundaries - Exposes detailed metrics via an admin HTTP interface on each service ## Architecture Overview Finagle is built on Netty for asynchronous I/O and uses Twitter's ``Future`` and ``Service`` abstractions. A ``Service`` is a function from request to ``Future[Response]``, and a ``Filter`` is a composable middleware that wraps services. Clients maintain connection pools and use a load balancer to distribute requests across endpoints discovered via service registries or DNS. ## Self-Hosting & Configuration - Add the protocol-specific module (``finagle-http``, ``finagle-thrift``, etc.) to your build tool - Configure via the builder pattern: ``Http.client.withRetries(...).withLoadBalancer(...)`` - Enable the admin HTTP server for metrics and health checks on a dedicated port - Deploy as a standard JVM process; no external sidecar required - Use Flags (Finagle's config system) or standard JVM properties for runtime tuning ## Key Features - Protocol-agnostic design supports HTTP/1.1, HTTP/2, Thrift, gRPC, MySQL, Redis, and Memcached - Composable filters let you layer cross-cutting concerns (auth, logging, tracing) cleanly - Aperture load balancer minimizes connections while distributing load fairly - Built-in distributed tracing compatible with Zipkin - Battle-tested at scale handling billions of requests per day at Twitter ## Comparison with Similar Tools - **gRPC** — focused on Protocol Buffers over HTTP/2; Finagle supports multiple protocols and richer client-side features - **Spring Cloud** — heavier Java ecosystem with config server and gateway; Finagle is a focused RPC library - **Akka HTTP** — actor-based model; Finagle uses futures and services for a simpler async model - **Netty** — raw async I/O framework; Finagle adds RPC semantics, load balancing, and observability on top - **Envoy** — sidecar proxy approach; Finagle is an in-process library with no extra deployment ## FAQ **Q: Can I use Finagle with Java?** A: Yes. While examples often use Scala, Finagle has a Java-friendly API and works well in pure Java projects. **Q: Is Finagle still actively maintained?** A: Yes. Twitter continues to maintain Finagle, and it powers critical infrastructure at X (formerly Twitter). **Q: How does Finagle compare to a service mesh?** A: Finagle handles load balancing, retries, and tracing in-process. A service mesh like Istio does similar work via sidecar proxies. Finagle avoids the extra hop but requires library integration. **Q: Does Finagle support HTTP/2?** A: Yes. The ``finagle-http`` module supports both HTTP/1.1 and HTTP/2 with configuration. ## Sources - https://github.com/twitter/finagle - https://twitter.github.io/finagle/ --- Source: https://tokrepo.com/en/workflows/asset-0eccef2e Author: Script Depot