Is switching from Express to Fiber worth it? 🤔
Tags: go, fiber, node, beginners
Published: 2020-04-01 22:18:33

## Introduction

Good news, everyone! 😉 We did it! **Fiber** version `1.8.43` scored awesome benchmark results! Now we hold a strong third place on [TechEmpower](https://www.techempower.com/benchmarks/#section=test&runid=02692910-4c3f-4c56-a9dc-f0167a4280a4&hw=ph&test=plaintext) as a full fledged Golang HTTP framework!

> ❗️ This post is not about if _Fiber is faster than Express_, this is obvious since Node.js is an interpreted language, while Golang is a compiled language. 
>
> ☝️ We mainly focus on testing **Fiber** versus other Go frameworks with the following disciplines: _plaintext_, _data updates_, _multiple queries_, _single query_ and of course, _JSON serialization_! 😎

## Table of contents

- [A few words about Fiber and Express](#ch-1)
- [Config of test stand](#ch-2)
- [Benchmark results](#ch-3)
  - [Plaintext](#ch-3-1)
  - [Data Updates](#ch-3-2)
  - [Multiple Queries](#ch-3-3)
  - [Single Query](#ch-3-4)
  - [JSON Serialization](#ch-3-5)
- [The choice is obvious](#ch-4)
- [Is it worth to switch to Go?](#ch-5)
- [Do you like Fiber?](#ch-6)
- [Your assistance to project](#ch-7)

<a name="ch-1"></a>
## 🍿 A few words about Express and Fiber

First of all, me and all Fiber authors love Express so much and made a lot of projects with it! But, **Fiber is different**.

- [Express](https://github.com/expressjs/express) — _extremely_ popular Node.js web framework. And still the best choice for JavaScript developers on backend.
- [Fiber](https://github.com/gofiber/fiber) — web framework, written in Golang with exactly the same API, like Expressjs. Focused on JavaScript developers and new gophers, who want to easily switch to Go on the backend.

<a name="ch-2"></a>
## ⚙️ Config of test stand

- **CPU** Intel Xeon Gold 5120 @2,20 GHz
- **MEM** 32 GB
- **GO** go1.13.6 linux/amd64
- **OS** Linux
- **DISK** Enterprise SSD
- **NET** Dedicated Cisco 10-gigabit Ethernet switch

> See [Project Information Framework Tests Overview](https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview) for more info.

<a name="ch-3"></a>
## 🤖 Benchmark results

<a name="ch-3-1"></a>
### Plaintext

The Plaintext test is an exercise of the request-routing fundamentals only, designed to demonstrate the capacity of high-performance platforms in particular.

- Requests will be sent using HTTP pipelining.
- The response payload is still small, meaning good performance is still necessary in order to saturate the gigabit Ethernet of the test environment.

![Plaintext](https://dev-to-uploads.s3.amazonaws.com/i/51ptmma35usfoiic65m5.png)

✅ Fiber handled **6,162,556** resp./sec with an average latency of **2.0** ms.

![Plaintext](https://dev-to-uploads.s3.amazonaws.com/i/tbpmxqqzscdk2lmiyg9f.png)

✅ Express handled **367,069** resp./sec with an average latency of **354.1** ms.

<a name="ch-3-2"></a>
### Data Updates

The Database Updates test is a variation of the Multiple database queries that exercises the ORM's persistence of objects and the database driver's performance at running UPDATE statements or similar.

The spirit of this test is to exercise a variable number of read-then-write style database operations.

![Data Updates](https://dev-to-uploads.s3.amazonaws.com/i/2eb505qm4qimpevqojri.png)

✅ Fiber handled **11,846** resp./sec with an average latency of **42.8** ms.

![Data Updates](https://dev-to-uploads.s3.amazonaws.com/i/ddutbixit0dtthgxovwj.png)

✅ Express handled **2,066** resp./sec with an average latency of **390.44** ms.

<a name="ch-3-3"></a>
### Multiple Queries

The Multiple Database Queries test is a variation of Single Database Query test and also uses the World table. Multiple rows are fetched to more dramatically punish the database driver and connection pool. 

At the highest queries-per-request tested (20), this test demonstrates all frameworks' convergence toward zero requests-per-second as database activity increases.

![Multiple Queries](https://dev-to-uploads.s3.amazonaws.com/i/ojspr38qsbhp2vnnd5j7.png)

✅ Fiber handled **19,664** resp./sec with an average latency of **25.7** ms.

![Multiple Queries](https://dev-to-uploads.s3.amazonaws.com/i/m7i30znwsqjsc2amqp3l.png)

✅ Express handled **4,302** resp./sec with an average latency of **117.2** ms.

<a name="ch-3-4"></a>
### Single Query

The Single Database Query test exercises the framework's object-relational mapper (ORM), random number generator, database driver, and database connection pool.

![Single Query](https://dev-to-uploads.s3.amazonaws.com/i/j89h6y663haicn7dplv8.png)

✅ Fiber handled **368,647** resp./sec with an average latency of **0.7** ms.

![Single Query](https://dev-to-uploads.s3.amazonaws.com/i/ovw0ttq11y18blm2wz47.png)

✅ Express handled **57,880** resp./sec with an average latency of **4.4** ms.

<a name="ch-3-5"></a>
### JSON Serialization

The JSON Serialization test exercises the framework fundamentals including keep-alive support, request routing, request header parsing, object instantiation, JSON serialization, response header generation, and request count throughput.

![JSON Serialization](https://dev-to-uploads.s3.amazonaws.com/i/5wgq7vkf5onoti6sp8xz.png)

✅ Fiber handled **1,146,667** resp./sec with an average latency of **0.4** ms.

![JSON Serialization](https://dev-to-uploads.s3.amazonaws.com/i/mrqug3l5rnleeodqq4mt.png)

✅ Express handled **244,847** resp./sec with an average latency of **1.1** ms.

<a name="ch-4"></a>
## ⚠️ The choice is obvious

If you haven't tried running your web projects in Go, [Fiber](https://github.com/gofiber/fiber) might be the right framework for you!

<a name="ch-5"></a>
## ❓ Is it worth to switch to Go?

It really depends on the use case. But it might benefit, if you need **more** performance.

<a name="ch-6"></a>
## 💬 Do you like Fiber? Tell about it!

Fiber authors are **always** listening to its users in [issues](https://github.com/gofiber/fiber/issues) and all over the Internet. Therefore, it would be great, if you could share your opinion or/and experience with **Fiber** to authors in [GitHub](https://github.com/gofiber/fiber) repository!

> [...] because it's only right way to create a **fast**, **flexible** and **friendly** Go web framework for any tasks, deadlines and developer skills!
>
> _— Fiber Authors_

![Do you like Fiber?](https://dev-to-uploads.s3.amazonaws.com/i/v22vk8sjujiixm7i1jfg.jpg)

<a name="ch-7"></a>
## Your assistance to project 👍

1. Add a [GitHub Star](https://github.com/gofiber/fiber) to project.
2. Tweet about Fiber [on your Twitter](https://twitter.com/intent/tweet?text=%F0%9F%9A%80%20Fiber%20is%20an%20Express%20inspired%20web%20framework%20written%20in%20%23Go%20with%20%F0%9F%92%96%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber).
3. Help to translate `README` and [API Docs](https://docs.gofiber.io/) to another language (_at this moment, Fiber was translated to **10** languages_).

## Photo by

[Title] Sonic from the Google Pictures
[1] Ashley McNamara https://github.com/ashleymcnamara/gophers

<a name=""></a>
## P.S.

If you want more articles (like this) on this blog, then post a comment below and subscribe to me. Thanks! 😻

And of course, you can help me make developers' lives even better! Just connect to one of my projects as a contributor. It's easy!

My projects that need your help (and stars) 👇

- 🔥 [gowebly][gowebly_url]: A next-generation CLI tool for easily build amazing web applications with Go on the backend, using htmx & hyperscript and the most popular atomic/utility-first CSS frameworks on the frontend.
- ✨ [create-go-app][cgapp_url]: Create a new production-ready project with Go backend, frontend and deploy automation by running one CLI command.
- 🏃 [yatr][yatr_url]: Yet Another Task Runner allows you to organize and automate your routine operations that you normally do in Makefile (or else) for each project.
- 📚 [gosl][gosl_url]: The Go Snippet Library provides snippets collection for working with routine operations in your Go programs with a super user-friendly API and the most efficient performance.
- 🏄‍♂️ [csv2api][csv2api_url]: The parser reads the CSV file with the raw data, filters the records, identifies fields to be changed, and sends a request to update the data to the specified endpoint of your REST API.
- 🚴 [json2csv][json2csv_url]: The parser can read given folder with JSON files, filtering and qualifying input data with intent & stop words dictionaries and save results to CSV files by given chunk size.

<!-- Footer links -->

[gowebly_url]: https://github.com/gowebly
[cgapp_url]: https://github.com/create-go-app
[yatr_url]: https://github.com/koddr/yatr
[gosl_url]: https://github.com/koddr/gosl
[csv2api_url]: https://github.com/koddr/csv2api
[json2csv_url]: https://github.com/koddr/json2csv