Best API Frameworks For Fast Performance

8 min read time
Best API Frameworks For Fast Performance

In previous articles, we compared high-performance development frameworks for front-end and back-end. This guide will look at the best frameworks for building fast APIs. 

The drive for rapid application development, robust security, and speed continues at pace in 2022. Today's users demand immediate responses from their favorite apps. Almost all web and mobile apps will use APIs in some form and so application delivery teams are constantly on the lookout for web frameworks that can deliver high-performance APIs. 

Let's compare the best options for developing high-performance APIs. 

Phoenix + Elixir

The Phoenix framework is a Model View Controller (MVC) web development framework written in Elixir. It's described on phoenixframework.org as 'MVC without the mess'. In the Stack Overflow 2022 developer survey, Phoenix made 21st position in the top 25 most popular web frameworks voted by professional developers. 

fast-api-frameworks-phoenix

Phoenix is designed for real-time applications and its MVC implementation focuses on productivity and maintainability. 

One of its high-performance features is Channels. Phoenix Channels enable real-time communication between clients. Channels are ideal for messaging APIs, breaking news, monitoring apps, or any use case that needs real-time events. They work by the client first connecting to the server e.g. via a WebSocket, once connected, they join a topic. Messages can then be pushed to a topic and received from it. The server can broadcast messages to clients subscribed to the Channel.

Channels are unlike stateless HTTP connections, they support long-lived connections. Working in parallel with a BEAM process, a Channel can maintain its own state. If you're wondering what BEAM is, it's basically like an incoming stream of data that may or may not ever terminate.

Phoenix Channel architecture can scale well, supporting millions of connected clients with low latency. This capacity can be extended when used with clusters and can pass hundreds of thousands of messages per second.

If you're building an MVC app, you may be interested in another helpful feature of Phoenix. The framework has pre-compiled templates that the documentation claims can give you 'blazing speed'. 

So it seems that Phoenix's scalable Channels and pre-compiled templates are a couple of high-performance features that make it worth a look.

Phoenix

Express.js + Node.js

Express.js and Node.js are one of the most popular framework combinations for building APIs. Node.js was the most popular web framework in the Stack Overflow 2022 developer survey, so it's unsurprising that Express.js was the 4th most popular framework among professional devs. Express scored 59% in the most loved poll.

fast-api-frameworks-express-js

Express is a flexible Node.js framework for creating robust APIs. It's a minimal framework that's ideal for single, multi-page, and hybrid applications. It has built-in HTTP utilities and middleware that make creating APIs quick and simple. You have to write hardly any code to create a basic Express API, as you can see from this example:

const express = require("express")

const app = express()

app.get("/api", (req, res) => {

  res.setHeader("content-type", "text/plain")

  res.send(`Hey ${req.query.name} ${req.query.name}`)

})

app.listen(4000)

When it comes to performance, Express is one of the faster options for implementing APIs. In some scenarios, such as synchronous mode, Express can outperform FastAPI by handling twice as many requests per second.

For anyone who isn't familiar with Express, one of the great things about it is its documentation. Their documentation is clear and detailed with code examples for every object and method making it super-easy to get up to speed. Express has flexibility in terms of version support too. It supports earlier versions of Node.js and ECMAScript (ES).

It's possible to create fast, minimal APIs with Express which makes it perfect for use within microservices. It's a great option for getting a high-speed, lightweight API up and running quickly.

Express.js

FastAPI

FastAPI is a Python 3.6+ framework designed for building APIs which conform to the OpenAPI (Swagger) standard. We've covered FastAPI before because it's a popular high-performance framework. Fast API made 15th in Stack Overflow's 2022 most popular web frameworks list. 

fast-api-frameworks-fastapiFastAPI is a micro-framework similar to Flask. In fact, Flask was one of the inspirations for FastAPI. FastAPI follows Flask's decoupling of parts making it easy to mix and match the tools you need for your project.

FastAPI is built to minimize code duplication and has automatic documentation. These features help to get your project to production-ready code quickly. 

It's based on Starlette and supports any Starlette code you already have, most of the functionality is the same. Similarly, the same applies to Pydantic, and it's also compatible with Pydantic ORMs.

FastAPI's speed comes from it being built over the Starlette ASGI (Asynchronous Server Gateway Interface) toolkit which enables multiple tasks to be run concurrently. Starlette is modular, extensible, and provides impressive performance. FastAPI uses Starlette to handle all of its core parts, the FastAPI class actually inherits directly from the Starlette class.

It's these underlying Starlette and Pydantic toolkits that make it one of the fastest available frameworks. Although they're from 2021, TechEmpower's most recent benchmarks for FastAPI are impressive, indicating that it's one of the fastest backend frameworks by comparison. 

FastAPI 

Fiber

Fiber is a minimal framework that's written in Go and is designed for rapid application development and high performance. It didn't make the top 25 in the Stack Overflow survey but that's likely to be because Go is still growing in popularity. Fiber is still a very fast API solution.

fast-api-frameworks-fiberThe Fiber framework is similar to Express.js. Building an app with Fiber can be done using a similar approach to combining Node.js and Express.js. Fiber uses many similar methods and principles as used in Express.js. Fiber combines the ease of Express with the performance of Go.

Fiber is built on top of the Fasthttp Go library which is designed to handle thousands of small to medium requests per second. Fasthttp has no memory allocation and this means it can perform up to 10 times faster than net/http. Fiber's extremely small memory footprint also helps development teams as they don't have to pay too much attention to memory management.

Fiber's minimalist design was created to allow developers to rapidly create backend apps and APIs. Experienced JavaScript developers will be comfortable working with Fiber even if they're new to Go. Fiber has also been translated into 15 languages and supports 8 templating engines including Handlebars, Django, and Amber.

Fiber is one of the fastest frameworks for building APIs. You can check out the latest benchmarks at TechEmpower.

Fiber

Fastify

Fastify is a fast JavaScript framework that made 19th in the Stack Overflow top 25 most popular frameworks.

fast-api-frameworks-fastifyFastify is designed with minimal footprint in mind and is capable of serving up to 30 thousand requests per second. The framework will also efficiently handle server resources without compromising security validation. An example that highlights its high performance is when it was used to create a COVID-19 tracking app. The Fastify tracking application sustained growth of zero to 1.5 million users in a few days. 

Fastify's plugin system is one of its key performance features. When handling a request, Fastify runs a minimal amount of functions. To explain this we can compare the functionality of Express and Fastify.

Express uses the middleware pattern, which means it processes requests sequentially – lists of functions execute one after another. Fastify uses the middleware pattern plus a tree data structure, which means it routes requests and executes them sequentially but only by the functions needed. The difference here is that Express middleware affects all requests and Fastify middleware only affects a limited number of requests.

A growing number of companies are choosing Fastify for its high performance, and you can see why they choose it for apps that need to handle huge volumes of requests.

Fastify

.NET Core

.NET is Microsoft's open-source general-purpose development platform. ASP.NET Core was the 6th most popular framework in this year's Stack Overflow poll, 72% who used it loved it.

fast-api-frameworks-net-coreMicrosoft has added many performance improvements in .NET 6. New language features reduce the amount of code you need to write. You might think that the myriad features and libraries that Microsoft provides would mean poor performance but that's not true with .NET 6. It's possible to build lightweight, high-performance APIs with this framework. As you can see from this example, a minimal REST API can be created with comparable simplicity to other frameworks like Express.

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.MapGet(“/platforms”, () => “Windows,Mac,Linux,Unix”);

app.Run();

Other performance improvements are FileStream, profile-guided optimization (PGO) that improves steady-state performance, and AOT (ahead-of-time) compilation. The latter is provided by the introduction of Crossgen2 which provides optimizations that weren't possible in previous versions. The addition of AOT improves the start-up time of your applications.

One of the major improvements is 'inlining'. Inlining is the process where the compiler takes the code from a method callee and emits it directly into the caller. The major benefit of this is that it exposes the contents of the method callee to the context of the caller, enabling subsequent optimizations that wouldn’t have been possible without the inlining. 

One of the downsides of coding .NET is that it's not ideal if you're a developer who likes to understand all the ins and outs of your code dependencies. The complex, nested structure of .NET makes it time-consuming to step down through dependencies so you just have to trust that the framework is handling everything. Also, .NET 6 isn't supported by Visual Studio 2022 but you can still create ASP.NET Core projects with this IDE. However, these are fairly insignificant issues when it comes to balancing performance and ease of use. 

There's been a significant performance boost to .NET 6 so it's well worth a look if you're building microservices within the Microsoft ecosystem. TechEmpowers 2022 composite benchmarks show that ASP.NET can outperform Express and FastAPI.  

.NET 6

Conclusion

We've looked at some of the most popular high-performance API frameworks in 2022. Each one has great features and all are perfect for microservice API development. 

  • The Starlette toolkit that underpins FastAPI makes it one of the fastest available frameworks for lightweight APIs. 
  • If you're building a communication app then Phoenix's scalable Channels are perfect for this use case. 
  • Fastify can handle huge volumes of requests and is capable of handling rapid growth in your userbase. 
  • If you need a low memory framework then Fiber is a great choice. It combines the simplicity of Express with the speed of Go. 
  • Node and Express are probably the most popular API frameworks in use and this is because of the minimal code and time necessary to create microservice APIs. 
  • Microsoft's release of .NET 6 has put the cat amongst the pigeons as it's now possible to create high-performance minimal-code microservice APIs with this framework. This could make it appear on the radar of product teams who would have previously discounted it.

To learn more about these and other API options check out the Stack Overflow 2022 Developer Survey and TechEmpower's Round 20 benchmarks.

Thank you for reading.

Why You Need An API Gateway To Manage Access To Your APIs

As APIs become increasingly crucial for running a business, it's critical to provide reliable and consistent service while protecting APIs from misuse or exploitation.

An API gateway provides a layer of security and control essential for protecting your data and keeping your APIs highly available. In this blog post, we'll explore the benefits.

snapt-nova-api-gateway-architecture-diagram

Subscribe via Email

Get daily blog updates straight to your email inbox.

You have successfully been subscribed!