Building Micro Services with .Net Core + Krakend API Gateway

Having an API gateway is one of the standard of building micro services. There are many open source and enterprise version gateways available in market. In terms of open source, Ocelot, Kong, Tyk are few of the popular gateways. Especially for .NET Core Web API projects, Ocelot is kind of goto framework.

While searching for fastest and reliable open source API Gateway, I stumbled upon KrakenD API gateway which is written in Go language. On their website, you can see the performance comparison with Kong and Tyk which is pretty impressive.

KrakenD vs other products in the market. Requests per second in equal conditions. See benchmarks

So to give it a try, I have built two services — UsersService and ProductsService in .NET Core 2.2 with basic CRUD operations and exposed their endpoints via KrakenD gateway. For sake of simplicity, I won’t go into how to write Web API services and DI of data services etc.

Refer to source code and README file in below repository to explore more.

  • Online API Gateway Designer KrakenD has online designer where you can work with your configuration if you prefer not to edit configuration file. You can download configuration from editor and/or upload file to modify it.
KrakenD api gateway designer

Route Mapping

Let’s understand a simple API gateway route mapping. In below gist, you can see that endpoint “/users” is mapped with “/api/users” backend endpoint.

Route mapping of /users to /api/users downstream service in krakend.json
  • endpoint: This is endpoint used with gateway address
  • output_encoding: type of output encoding. Note that, if your backend doesn’t sends any response set this value to “no-op” otherwise you will get an error.
  • backend: Configuration for your backend API.
  • backend/host: Address of downstream service
  • backend/url_pattern: endpoint of downstream service to hit
  • backend/is_collection: if downstream service sends an array of objects then this property should be set.
  • backend/encoding: type of output encoding. Note that, if your backend doesn’t sends any response set this value to “no-op” otherwise you will get an error.

KrakenD has very good documentation and slack channel for discussion.

I think KrakenD has bright future. Their enterprise product and services looks promising. Based on open source community feedback and usage, I hope they will keep adding more features and support for community edition as well.

krakend.json file products and users micro services CRUD operations

Cloud Solution Architect | Author | Full Stack Developer | https://www.linkedin.com/in/balram-chavan | https://www.hiretheauthor.com/balramchavan

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store