Simplify API Gateway Extensibility: Kono vs. KrakenD Architectures
These articles are AI-generated summaries. Please check the original sources for full details.
Extending your API gateway without forking it
Alexander Pikeev introduces Kono, a gateway architecture focusing on low-boilerplate extensibility. A minimal KrakenD modifier requires roughly 60 lines of boilerplate before business logic, whereas Kono uses direct SDK methods.
Why This Matters
In technical practice, most API gateways are extensible only in theory, requiring engineers to read internal source code for hours to implement simple business logic. This high entry cost often results in indirection-heavy codebases where developers must copy-paste interface definitions to avoid dependency collisions, as seen in systems utilizing complex registerer symbols. Kono addresses this by aligning plugin architecture with standard Go HTTP handlers and offloading scripting to a separate LuaJIT process. This design prioritizes clear contracts over ‘magic’ abstractions, reducing the maintenance burden of custom gateway modifications.
Key Insights
- KrakenD plugin registration requires a ModifierRegisterer and factory functions, resulting in approximately 60 lines of boilerplate for a single request modifier.
- Kono plugins utilize a minimal SDK surface consisting of only four methods: Info(), Type(), Init(), and Execute().
- The Kono ‘snakeify’ plugin performs recursive JSON key transformation in 100 lines of code, with only 30 lines dedicated to SDK overhead.
- Lumos provides a Lua scripting layer that runs as a separate LuaJIT process, communicating via Unix sockets to avoid Go binding overhead.
- Communication between the gateway and Lumos uses a length-prefixed JSON protocol, achieving latency measured in microseconds.
Working Examples
KrakenD boilerplate for registering a modifier via factory functions
var ModifierRegisterer = registerer("my-plugin")
func (r registerer) RegisterModifiers(f func(
name string,
factoryFunc func(map[string]interface{}) func(interface{}) (interface{}, error),
appliesToRequest bool,
appliesToResponse bool,
)) {
f(string(r)+"-request", r.requestHandler, true, false)
}
Kono plugin implementation providing direct access to the HTTP response body
func (p *Plugin) Execute(ctx sdk.Context) error {
resp := ctx.Response()
if resp == nil || resp.Body == nil {
return nil
}
// read body, transform, replace
resp.Body = io.NopCloser(bytes.NewReader(newBody))
return nil
}
Kono middleware using standard Go http.Handler wrapping
func (m *Middleware) Handler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// before request
next.ServeHTTP(w, r)
// after response
})
}
Practical Applications
- JSON Transformation: Use Kono plugins to recursively transform JSON keys to snake_case with minimal SDK surface; Pitfall: Using interface{} type assertions in modifiers can lead to runtime errors if the wrapper definition is incorrect.
- High-Performance Scripting: Deploy Lumos for token validation and header injection using LuaJIT over Unix sockets; Pitfall: Embedding Lua interpreters directly into Go processes can accumulate significant binding overhead under heavy load.
References:
Continue reading
Next article
Scaling Enterprise Infrastructure with AutoBot and Ansible Orchestration
Related Content
Bypassing Vercel Serverless Timeouts with a Decoupled Document Ingestion Pipeline
Engineer Edwin solves Vercel serverless timeouts by decoupling Next.js API routes from a persistent BullMQ worker architecture on Railway.
WSO2 AI Gateway vs Kong: Choosing the Right Platform for Your AI Strategy
AI gateways are revolutionizing API management with WSO2 and Kong emerging as leaders, offering distinct architectural approaches to handle AI agent traffic.
Automating Hidden JSON API Discovery for Robust Web Scraping
Developer Alex Spinov released a Node.js script that replaces fragile HTML scraping with direct JSON API access, achieving a 10x speed increase and reducing code from 120 to 15 lines.