XenonStack Recommends

Enterprise Digital Platform

Understanding KrakenD API Gateway for Microservices

Navdeep Singh Gill | 06 Jun 2023

KrakenD: A High-performance API Gateway for Microservices

Introduction to KrekenD

KrekenD is a very High-performance API gateway. It's Open Source in nature. It provides a very reliable entry point for clients to microservices. KrakenD helps Create API as an aggregator of multiple microservices into single endpoints. It focuses on doing the heavy work like decode, throttle, auth, transform, aggregate automatically.
It provides a declarative way to create the endpoints and has the community developed a plug n play middleware.

KrakenD does not require programming language as it has a declarative way to create endpoints. As it is a PURE API gateway, KrakenD avoids coupling the API gateway to the HTTP transport layer.

The microservices architecture style is an approach for developing small services each running in its process. Click to explore about, Microservices Architecture and Design Patterns

What is an API Gateway for Microservices?

The assemblage-oriented programming that resides in front of a particular Application Programming Interface or API, along with being the single point of entry for various microservices and defined Back-end APIs being either internal or external, is referred to as an API gateway. This module(API gateway) acts as a protector, helps ensure high availability, scalability and security.

It takes all the API requests from the client and determines if and which services are required. It then combines these services into a unified and projectively seamless experience for the user. An API gateway helps provide performance, high availability, and elasticity by enabling involved enterprises to instantiate deliveries with defined and uniform supporting services, including traffic management, system integration, and transformation. API Gateway also manages and creates the WebSocket APIs that:

  • Adhere to the WebSocket protocol, which allows stateful, full-duplex communication between client and server.
  • Route incoming messages based on message content.

API Gateway acts as a "front door" for the applications to access data, business logic, or functionality from your backend services. Likewise, workloads running on Amazon EC2 (Amazon Elastic Compute Cloud), code running on AWS Lambda, web application, or real-time communication applications.

Looking at the below-provided diagram, we can understand how the API gateway comes into the picture.

The Rust compiler is one of the most used open-source programming language compiler built to create robust and efficient software. Click to explore about, Golang vs Rust - The Race to Better and Ultimate Programming Language

Using KrekenD in Command Line

The krakend run command can be used to run the krakend server via the command line. We can begin by invoking the terminal's run command and the path to the configuration file. We may specify the port(8080 as default) also.

$ krakend run -- config/path/to/krakend.json -p 8080

Or,

$ krakend run -- config/path/to/krakend.json

Or,

$ krakend run -- c krakend.json

If no flags are provided, a message is displayed with "Please, provide the path to your config file."

For more options, use the -h or help flag :

The most widely used command for setting up the krakend server is

$ krakend run -- config krakend.json

To start the server in a different port, we can set the port in the configuration file or pass its flag as given below.

$ krakend run -- config krakend.json -- port 8899

What are the features of KrakenD?

There are numerous extensive features that KrakenD provides to its user Base. Some of the most significant ones are listed below :

  • Aggregation of information from multiple sources into central endpoints.
  • Manipulation of responses along with grouping and wrapping.
  • Filtering and shrinking of responses, Enabling abstraction.
  • Rate limiting connections
  • Enables circuits breakers and other security measures
  • Provides multiple encoding formats and protocols.
  • Supports numerous other middlewares and plugins, like authentication with Oauth, etc.
  1. Management of DSL(digital subscriber line) configurations.
  2. Cross-site scripting support.
  3. HPKP support(HTTP public key Pinning)
  4. Host-based connection restrictions.
  5. User quota management.
  6. SSL support.
  7. OAuth CCG support (Client credential grant)
  8. ClickJack protection support.

Postman vs Nginx vs MuleSoft vs KrekenD

Let us now compare some of the most similar products available in the market that are well established and provide a similar range of features as that by the krakend API gateway service.

Feature Tag Postman MuleSoft KrekenD
API Design ✔️ ✔️ ✔️
API Lifecycle Management ✔️ ✔️ ✔️
Access Control ✔️ ✔️ ✔️
Analytics ✔️ ✔️ ✔️
Dashboard ✔️ ✔️ ✔️
Developer Portal ✔️ ✔️ ✔️
Testing Management ✔️ ✔️ ✔️
Threat Protection   ✔️ ✔️
Traffic Control   ✔️ ✔️
Version Control ✔️   ✔️
Deployment
Feature Tag Postman MuleSoft KrekenD Nginx
SaaS/Web/Cloud ✔️ ✔️ ✔️ ✔️
Mobile - Android ✔️ ✔️   ✔️
Mobile - iOS   ✔️   ✔️
Mobile - Windows       ✔️
Mobile - BlackBerry        
Installed - Windows ✔️   ✔️ ✔️
Installed - Mac ✔️   ✔️ ✔️
Customers
Feature Tag Postman MuleSoft KrekenD Nginx
Individuals       ✔️
Freelancers   ✔️ ✔️  
Large Enterprises ✔️ ✔️   ✔️
Medium Business ✔️ ✔️ ✔️ ✔️
Small Business ✔️ ✔️ ✔️ ✔️
API service ✔️ ✔️ ✔️  

What are the basic developer Tools?

KrakenD provides tools for the developer to use in the development stage (not for the production stage). Below are provided some of the widely used and helpful tools available :

  1. Config2dot: Helps create graphs automatically after reading the krakend.json file.
  2. Hot reload for configuration: Helps test new changes without having to restart the whole server as we have a docker image using Reflex watching the config directory and automatically reloads krakenD when config changes.
  3. Krakend-memviz: Provides a DOT file exporter of request/response snapshots to proxy stack for debugging and development purposes. It slows down the performance highly so as not to be used in production.
  4. Krakend-spew: It provides a dump for every entity seen in the pipe. Every request and response has to pass through the whole stack. Dumps are then saved in files as:

<pipe>_<base64_endpoint/backend_name>_<timestamp>.txt

cloud-managed-services-card-icon
Our solutions cater to diverse industries with a focus on serving ever-changing marketing needs. Click to explore our Managed Services for Microservices

How KrakenD will perform on Benchmarking Standards?

The main question that comes to mind regarding krakend is how it will perform on benchmarking standards. As krakend is an additional layer on top of the existing structure, the performance aspect makes it just that more vital. Below are provided some of the general use case-based benchmarks :

  • 18,000 req/sec on an ordinary laptop: below are provided a summarization of tests done on a laptop with Amazon EC2 instances.
  Hardware Specs Requests Second Average Response
1 Amazon EC2 (c4.2xlarge) 10126.1613 reqs/s 9.8ms
2 Amazon EC2 (c4.xlarge) 8465.4012 reqs/s 11.7ms
3 Amazon EC2 (m4.large) 3634.1247 reqs/s 27.3ms
4 Amazon EC2 (t2.medium) 2781.8611 reqs/s 351.3ms
5 Amazon EC2 (t2.micro) 2757.6407 reqs/s 35.8ms
6 MacBook Pro 2.2 GHz Intel Core i7 18157.4274 reqs/s 5.5ms
  • Benchmarking krakend with other products in the Market :

Products compared in the Below Results are krakend, Tyk,Vulcand,Kong.

Service req/sec
none 7534.6
KrakenD 3479.2
Vulcand 1979
Kong 1753.8
Tyk 450.2

Response time distribution(ms)

gateway

10%

25%

50%

75%

99%

min

max

avg

KrakenD

21.3

23.1

24.5

29.5

77.1

0.9

278.1

28.7

Vulcand

29.0

37.8

49.0

57.1

205.7

1.0

342.6

50.5

Kong

40.7

43.5

46.1

49.7

235.5

7.6

1597.8

56.9

Tyk

35.5

52.1

82.3

178.5

2105.4

1.2

5648.2

221.5

Conclusion

KrekenD API gateway service is a very efficient and productivity-centric tool, designed with mind the performance aspect. It can provide a great upgrade in performance for enterprises or users that switch from almost any of its competitions available in the market. It's an Open Source platform providing a single interface Model. It also allows automated transformation, shrinking, picking, merging, and data based on user-defined parameters. It is not required to know any specific programming language for using KrekenD. The behavior of the software configuration can be edited by using the KrekenD designer or manually.