Skip to content

Guide · Open source

How to use fasthttp: install and build a Go HTTP server

Updated · written with AI from the project's own documentation and checked against our catalogue data

fasthttp is an HTTP server and client package for the Go programming language, built to be faster than Go's standard net/http package. This guide explains what it is, when it is worth using, how to get the source, and what to check before you switch. By the end you will know whether fasthttp fits your project and where to find its documentation and examples.

fasthttpvalyala/fasthttp · ★ 23.5k · MIT

Quick start

  1. 1Install Go. fasthttp requires Go. Install Go before anything else.
  2. 2Clone the repository. Run git clone https://github.com/valyala/fasthttp to get the source and examples.
  3. 3Read the examples. Open the examples directory and the pkg.go.dev documentation to learn the API.
  4. 4Write a small server. Adapt an example into a minimal server so you can test the API.
  5. 5Benchmark against net/http. Run the README benchmark commands and your own workload to measure the difference.
  6. 6Decide. Keep fasthttp only if measured HTTP handling is a real bottleneck and the API trade-offs are acceptable.

What fasthttp is and when it fits

fasthttp is a Go package that provides both an HTTP server and an HTTP client. It is designed to reduce memory allocations in its hot paths, which the README says gives higher throughput than net/http.

The README is direct about its limits: fasthttp was designed for some high performance edge cases, and for most cases net/http is much better because it is easier to use and can handle more cases. For most cases you may not notice the performance difference.

  • Good fit: your server or client must handle thousands of small to medium requests per second and needs consistent low millisecond response times.
  • Good fit: you have measured net/http and found HTTP handling to be a real bottleneck.
  • Good fit: you run a very high number of keep-alive connections, as VertaMedia does according to the README.
  • Poor fit: a typical Go web service, beginners learning Go web development, or projects that need broad compatibility with net/http handlers and middleware.

Install fasthttp with Go

The README lists Go as the prerequisite. The install method it documents is to clone the repository with git. Install Go first, then fetch the source with the command below.

The README does not show a separate package-manager command, so check the project documentation on pkg.go.dev for how to add the package to a Go module.

git clone https://github.com/valyala/fasthttp

Build a server and a client

The README links to code examples in the examples directory and to examples on the pkg.go.dev documentation page. Start from those rather than writing the API from memory, because fasthttp's API differs from the standard library.

Because handlers and request objects work differently from net/http, existing net/http handlers will need adapting. Plan for that before you migrate.

  • Open the examples directory in the cloned repository.
  • Compare each example with the pkg.go.dev documentation for the exact function signatures.
  • Keep your first version small so you can measure it against your current net/http code.

Measure before you switch from net/http

The README publishes benchmark results comparing fasthttp with net/http on a specific Intel Xeon machine, with GOMAXPROCS set to 1 and 4. In those runs fasthttp server results show 0 B/op and 0 allocs/op, while net/http shows dozens of allocations per request. The README states the server is up to 6 times faster than net/http and the client up to 4 times faster.

These numbers come from the author's hardware and test setup. Run the benchmark commands on your own code and workload before deciding, since the README itself says most projects will not notice the difference.

  • Server benchmark: GOMAXPROCS=1 go test -bench=kServerGet -benchmem -benchtime=10s (run from the repository).
  • Client benchmark: GOMAXPROCS=1 go test -bench='kClient(Do|GetEndToEnd)' -benchmem -benchtime=10s.
$ GOMAXPROCS=1 go test -bench=kServerGet -benchmem -benchtime=10s

Check the trade-offs before you commit

The main cost is compatibility. Because the API is not the standard library's, code written for net/http handlers and middleware may need changes, and the README notes that net/http can handle more cases.

Choose fasthttp when measured HTTP handling is your bottleneck and your team is comfortable adapting code to a non-standard API. Otherwise net/http remains the simpler choice.

  • Compare with net/http first, since the README recommends it for most projects.
  • Other Go web frameworks listed as comparable projects are Fiber, Gin and Echo.

What people use it for

  • Serving a high volume of small to medium HTTP requests per second from a Go service.
  • Handling a very large number of keep-alive connections on a single server, as VertaMedia does.
  • Building a high-throughput HTTP client in Go where client overhead matters.
  • Benchmarking HTTP handling in Go against net/http to see if the speed gain is real for your workload.

Frequently asked questions

Is fasthttp free to use?

fasthttp is released under the MIT licence, as listed in the project information. Check the LICENSE file in the repository for the full terms.

What do I need to install fasthttp?

The README lists Go as the prerequisite. Install Go, then clone the repository with git clone https://github.com/valyala/fasthttp.

Is fasthttp faster than net/http?

The README says the fasthttp server is up to 6 times faster and the client up to 4 times faster than net/http in its benchmarks. Those results come from the author's hardware, so measure your own workload before deciding.

Should I use fasthttp instead of net/http?

Usually not. The README says net/http is much better for most cases because it is easier to use and handles more cases. Consider fasthttp only if HTTP handling is a measured bottleneck.

What are the alternatives to fasthttp?

Projects listed as comparable include net/http, Fiber, Gin and Echo. net/http is the standard library option and is easier to use for most projects.

Why does fasthttp need code changes?

Its API differs from the standard library, so handlers and middleware written for net/http may need adapting. The README notes that net/http can handle more cases.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

fasthttp suits Go developers who have measured net/http as a real bottleneck and who handle very high request or keep-alive volumes, and who are comfortable with a non-standard API. Most Go web services, beginners, and projects that rely on net/http middleware should choose net/http or a framework such as Gin, Echo or Fiber instead.

Install options & downloads