API Cloud Architecture

TL;DR: A proposal for API gateway architecture using Kong for managing organization APIs with authentication, rate limiting, and pipeline routing.

Technical proposal for API gateway infrastructure

Overview

This document outlines the architecture for an API cloud platform using Kong as the gateway. The platform enables organizations to expose APIs with authentication, rate limiting, and intelligent routing to backend ML pipelines.

API Blueprint

Figure 1: API Cloud Architecture Blueprint

Flow Configuration

The following attributes define a customer API rollout:

Organization Attributes

{
    "organization": "ITU",
    "zone": "swatantra",
    "theme": "sales"
}

Credential Map

{
    "apiuser": "vinay",
    "apikey": "ENTER_KEY_HERE"
}

Pipeline Map

Routes requests to appropriate ML pipelines:

{
    "pmap": [
        {
            "pipeuse": "csim",
            "pipeip": "192.168.5.98",
            "pipeakey": "abcdefghijklmnopqrstu",
            "pipeport": "17092"
        },
        {
            "pipeuse": "ureco",
            "pipeip": "192.168.5.99",
            "pipeakey": "klfmnopqrstabcdefghij",
            "pipeport": "17093"
        }
    ]
}

Policies

{
    "policies": {
        "ratelimit": 200,
        "quota": 500000
    }
}

Complete Configuration Example

{
    "organization": "ITU",
    "zone": "swatantra",
    "subject": "sales",
    "cmap": {
        "apiuser": "vinay",
        "apikey": "ENTER_KEY_HERE"
    },
    "pmap": [
        {
            "pipeuse": "csim",
            "pipeip": "192.168.5.98",
            "pipeakey": "abcdefghijklmnopqrstu",
            "pipeport": "17092"
        }
    ],
    "dlink": "api.organisation.one/docs/sales/ingest",
    "policies": {
        "ratelimit": 200,
        "quota": 500000
    },
    "service": {
        "servicename": "itusales",
        "serviceurl": "h.one/cerebro/itu/swatantra/sales",
        "upstreamurl": "192.168.5.100:8080/cerebro/sales",
        "routehost": "itu.organisation.one",
        "routepaths": "h.one/cerebro/itu/swatantra/sales"
    }
}

API Routing Patterns

PatternExampleUse Case
Common Public APIapi.h.one/ingestPublish friendly
Granular Pathapi.h.one/itu/swantantra/sales/ingestDeveloper friendly
Subdomain Baseditu.h.one/sales/ingestDocumentation friendly
Organization Basedh.one/itu/ingestDeployment friendly

Setup Procedure

Step 1: Create Service and Route

# Add service
curl -i -X POST \
  --url http://localhost:8001/services/ \
  --data 'name=itu-service' \
  --data 'url=http://mockbin.org/request'

# Add route
curl -i -X POST \
  --url http://localhost:8001/services/itu-service/routes \
  --data 'paths[]=/ingest'

# Verify configuration
curl -i -X GET --url http://localhost:8000/ingest

Step 2: Create Consumer

# Enable key-auth plugin
curl -i -X POST \
  --url http://localhost:8001/services/itu-service/plugins/ \
  --data 'name=key-auth'

# Create consumer
curl -i -X POST \
  --url http://localhost:8001/consumers/ \
  --data "username=motoko"

# Provision credentials
curl -i -X POST \
  --url http://localhost:8001/consumers/motoko/key-auth/ \
  --data 'key=ENTER_KEY_HERE'

# Verify
curl -i -X GET \
  --url http://localhost:8000/ingest \
  --header "apikey: ENTER_KEY_HERE"

Step 3: Enable Request Transformer

Append pipeline information to requests:

curl -X POST http://localhost:8001/plugins \
  --data "name=request-transformer" \
  --data "consumer.id={consumer_id}" \
  --data "config.append.body=pipeuse:csim, pipeip:192.168.5.98, pipeakey:abcdefgh, pipeport:17092"

Step 4: Apply Policies

# Add rate limiting
curl -X POST http://localhost:8001/plugins \
  --data "name=rate-limiting" \
  --data "consumer.id={consumer_id}" \
  --data "config.minute=10"

Step 5: Declarative Configuration

Configuration can be applied through:

  • REST API calls
  • JSON with hot reload
  • YAML with hot reload

API Matrix

Interface Details

APINameDescription
a_csimContent SimilarityDiscover similar documents within vector space
a_preurecoPre-determined User RecommendationsCold-start solution for user recommendations
a_posturecoPost-determined User RecommendationsCollaborative filtering for user discovery
a_wnextWhat Next?Recommended next steps for efficient outcomes
a_crecoContext RecommendationsDiscover relevant contexts for users

Physical Pipelines

PipelineAPIs ServedComponentPurpose
p_csima_csim, a_preurecocontent-similarityWord2Vec text similarity
p_urecoa_preureco, a_postureco, a_wnext, a_crecorecommend-users-for-contextsUser recommendations

Installation

Standalone Setup

# Install Kong
sudo apt-get update
sudo apt-get install -y apt-transport-https curl lsb-core
echo "deb https://kong.bintray.com/kong-deb `lsb_release -sc` main" | sudo tee -a /etc/apt/sources.list
curl -o bintray.key https://bintray.com/user/downloadSubjectPublicKey?username=bintray
sudo apt-key add bintray.key
sudo apt-get update
sudo apt-get install -y kong

Cassandra Configuration

-- Create keyspace
CREATE KEYSPACE kong WITH REPLICATION = {
    'class': 'SimpleStrategy',
    'replication_factor': 1
};

-- Create user and role
CREATE USER kong WITH PASSWORD = 'kong' AND LOGIN = true;
CREATE ROLE kong_admin;
GRANT ALL PERMISSIONS ON KEYSPACE kong TO kong_admin;
GRANT CREATE ON ALL KEYSPACES TO kong_admin;
GRANT kong_admin TO kong;

Kong Configuration

Edit /etc/kong/kong.conf:

database = cassandra
cassandra_contact_points = xxx.xxx.xxx.xxx
cassandra_keyspace = kong
cassandra_username = kong
cassandra_password = xxxxxxxxxx
db_update_propagation = 60

Start Kong

kong migrations bootstrap [-c /path/to/kong.conf]
kong start [-c /path/to/kong.conf]
curl -i http://localhost:8001/

References


This proposal outlines the foundation for a scalable API gateway. Cluster deployment extensions are available for production environments.