Skip to main content

Overview

These endpoints demonstrate three different approaches to fetching cryptocurrency market data, showcasing KrakenD’s caching and concurrent processing capabilities. Endpoints:
  • GET /market/cached - With HTTP caching enabled
  • GET /market/simple - Standard processing
  • GET /market/concurrent - With concurrent calls enabled

What It Demonstrates

  • HTTP Caching: Backend response caching to reduce API calls
  • Concurrent Calls: Parallel processing for improved performance
  • Performance Comparison: Different strategies for the same data

GET /market/cached

Description

Fetches cryptocurrency market data with HTTP caching enabled at the backend level. Responses are cached and shared across requests.

Request Example

curl http://localhost:8080/market/cached

Expected Response

{
  "coins": [
    {
      "id": "bitcoin",
      "symbol": "btc",
      "name": "Bitcoin",
      "image": "https://assets.coingecko.com/coins/images/1/large/bitcoin.png",
      "current_price": 43250.50,
      "market_cap": 846000000000,
      "ath": 69045,
      "ath_change_percentage": -37.4
    },
    {
      "id": "ethereum",
      "symbol": "eth",
      "name": "Ethereum",
      "current_price": 2890.75,
      "market_cap": 347000000000
    }
  ]
}

Configuration

{
  "@comment": "Feature: Backend cache",
  "endpoint": "/market/cached",
  "backend": [
    {
      "host": ["https://api.coingecko.com"],
      "url_pattern": "/api/v3/coins/markets?vs_currency=eur&ids=bitcoin%2Cethereum&order=market_cap_desc&per_page=100&page=1&sparkline=false",
      "encoding": "safejson",
      "mapping": {
        "collection": "coins"
      },
      "extra_config": {
        "qos/http-cache": {
          "shared": true
        }
      }
    }
  ]
}

Key Features

HTTP Cache (qos/http-cache):
  • Shared: true - Cache is shared across all concurrent requests
  • Behavior: Respects HTTP cache headers from the backend (CoinGecko API)
  • Benefits: Reduces backend API calls, improves response times, lowers costs

GET /market/simple

Description

Fetches the same cryptocurrency market data without caching or concurrent processing. This is the baseline configuration.

Request Example

curl http://localhost:8080/market/simple

Expected Response

Same structure as /market/cached.

Configuration

{
  "@comment": "Feature: Concurrent calls - Not enabled",
  "endpoint": "/market/simple",
  "backend": [
    {
      "host": ["https://api.coingecko.com"],
      "url_pattern": "/api/v3/coins/markets?vs_currency=eur&ids=bitcoin%2Cethereum&order=market_cap_desc&per_page=100&page=1&sparkline=false",
      "encoding": "safejson",
      "mapping": {
        "collection": "coins"
      }
    }
  ]
}

Key Features

  • No caching configured
  • No concurrent processing
  • Standard sequential execution
  • Useful as a baseline for performance comparison

GET /market/concurrent

Description

Fetches cryptocurrency market data with concurrent calls enabled. This allows KrakenD to make the same request multiple times in parallel.

Request Example

curl http://localhost:8080/market/concurrent

Expected Response

Same structure as other market endpoints.

Configuration

{
  "@comment": "Feature: Concurrent calls - Enabled",
  "endpoint": "/market/concurrent",
  "concurrent_calls": 3,
  "backend": [
    {
      "host": ["https://api.coingecko.com"],
      "url_pattern": "/api/v3/coins/markets?vs_currency=eur&ids=bitcoin%2Cethereum&order=market_cap_desc&per_page=100&page=1&sparkline=false",
      "encoding": "safejson",
      "mapping": {
        "collection": "coins"
      }
    }
  ]
}

Key Features

Concurrent Calls:
  • concurrent_calls: 3 - Makes 3 parallel requests to the same backend
  • Behavior: Returns the fastest successful response
  • Benefits: Improved reliability and latency in unstable networks
  • Trade-off: Increases backend load by 3x

Performance Comparison

EndpointCachingConcurrent CallsBest Use Case
/market/cached✅ Yes❌ NoHigh-traffic APIs with stable data
/market/simple❌ No❌ NoReal-time data, low traffic
/market/concurrent❌ No✅ Yes (3x)Unreliable backends, latency-critical

Backend Service

All three endpoints call the same backend:
  • Host: https://api.coingecko.com
  • URL: /api/v3/coins/markets
  • Parameters:
    • vs_currency=eur
    • ids=bitcoin,ethereum
    • order=market_cap_desc
    • per_page=100
    • page=1
    • sparkline=false

Use Cases

/market/cached

  • Public market data APIs
  • Dashboard applications
  • Reducing third-party API costs
  • High-traffic scenarios

/market/simple

  • Real-time trading data
  • Low-latency requirements
  • Frequently changing data

/market/concurrent

  • Unreliable network conditions
  • Mission-critical applications
  • Geographic distribution with varying latency
  • Failover scenarios

Testing Performance

Compare response times:
# Test cached endpoint (first call)
time curl http://localhost:8080/market/cached

# Test cached endpoint (subsequent calls - should be faster)
time curl http://localhost:8080/market/cached

# Test simple endpoint
time curl http://localhost:8080/market/simple

# Test concurrent endpoint
time curl http://localhost:8080/market/concurrent

Build docs developers (and LLMs) love