How to Integrate LangGraph for lending with Kubernetes for startups

By Cyprian AaronsUpdated 2026-04-21
langgraph-for-lendingkubernetesstartups

LangGraph gives you the orchestration layer for lending workflows: document intake, policy checks, risk scoring, human review, and decisioning. Kubernetes gives you the runtime layer to run those agents reliably under load, isolate tenant workloads, and scale out when a startup starts pushing real traffic.

The useful pattern here is simple: LangGraph handles the lending state machine, while Kubernetes runs each node or worker as a containerized service. That lets you build an agent system that can pre-screen loans, route exceptions, and keep compliance logic versioned and deployable.

Prerequisites

  • Python 3.10+
  • A running Kubernetes cluster
    • local: kind, minikube, or k3d
    • cloud: EKS, GKE, or AKS
  • kubectl configured and pointing at your cluster
  • Docker installed for building images
  • Access to a LangGraph-compatible lending workflow package
  • Python packages:
    • langgraph
    • kubernetes
    • pydantic
    • requests
  • A Kubernetes namespace for your agent system
  • A service account with permissions to create Jobs or Deployments

Integration Steps

  1. Build the lending graph in LangGraph

    Start with a small state machine that takes an application through intake, scoring, and decisioning. In production, each node should be deterministic and side-effect free where possible.

    from typing import TypedDict, Literal
    from langgraph.graph import StateGraph, END
    
    class LendingState(TypedDict):
        applicant_id: str
        income: float
        debt: float
        score: int
        decision: Literal["approve", "review", "reject"]
    
    def intake(state: LendingState) -> LendingState:
        return state
    
    def score_application(state: LendingState) -> LendingState:
        dti = state["debt"] / max(state["income"], 1)
        score = 850 if dti < 0.2 else 650 if dti < 0.4 else 450
        return {**state, "score": score}
    
    def decide(state: LendingState) -> LendingState:
        if state["score"] >= 750:
            decision = "approve"
        elif state["score"] >= 600:
            decision = "review"
        else:
            decision = "reject"
        return {**state, "decision": decision}
    
    builder = StateGraph(LendingState)
    builder.add_node("intake", intake)
    builder.add_node("score_application", score_application)
    builder.add_node("decide", decide)
    
    builder.set_entry_point("intake")
    builder.add_edge("intake", "score_application")
    builder.add_edge("score_application", "decide")
    builder.add_edge("decide", END)
    
    lending_graph = builder.compile()
    
  2. Wrap the graph in a container-friendly worker

    Kubernetes works best when each process has one job. Expose the LangGraph workflow behind a small Python entrypoint so it can run as a pod or job.

    import json
    from langgraph.graph import StateGraph, END
    
    def run_lending_workflow(payload: dict) -> dict:
        result = lending_graph.invoke(payload)
        return result
    
    if __name__ == "__main__":
        sample = {
            "applicant_id": "app_1001",
            "income": 120000,
            "debt": 18000,
            "score": 0,
            "decision": "review",
        }
        output = run_lending_workflow(sample)
        print(json.dumps(output))
    
  3. Use the Kubernetes Python client to submit lending jobs

    For startups, Jobs are often the cleanest way to process applications asynchronously. You can create one Job per loan batch or per high-value application.

    from kubernetes import client, config
    
    config.load_kube_config()
    
    batch_v1 = client.BatchV1Api()
    
    job_manifest = client.V1Job(
        metadata=client.V1ObjectMeta(name="lending-eval-job"),
        spec=client.V1JobSpec(
            template=client.V1PodTemplateSpec(
                metadata=client.V1ObjectMeta(labels={"app": "lending-eval"}),
                spec=client.V1PodSpec(
                    restart_policy="Never",
                    containers=[
                        client.V1Container(
                            name="lending-worker",
                            image="ghcr.io/your-org/lending-worker:latest",
                            image_pull_policy="IfNotPresent",
                            env=[
                                client.V1EnvVar(name="APP_ENV", value="prod"),
                                client.V1EnvVar(name="NAMESPACE", value="ai-agents"),
                            ],
                        )
                    ],
                ),
            ),
            backoff_limit=2,
        ),
    )
    
    response = batch_v1.create_namespaced_job(namespace="ai-agents", body=job_manifest)
    print(response.metadata.name)
    
  4. Trigger graph execution from inside the cluster

    If you want event-driven behavior, run an API service in Kubernetes that accepts applications and invokes the LangGraph workflow. This is cleaner than pushing all logic into the pod startup command.

     from fastapi import FastAPI
     from pydantic import BaseModel
     from kubernetes import client, config
    
     app = FastAPI()
     config.load_incluster_config()
    
     class Application(BaseModel):
         applicant_id: str
         income: float
         debt: float
    
     @app.post("/evaluate")
     def evaluate(application: Application):
         payload = {
             "applicant_id": application.applicant_id,
             "income": application.income,
             "debt": application.debt,
             "score": 0,
             "decision": "review",
         }
         result = lending_graph.invoke(payload)
         return result
    
  5. Scale workers based on queue depth or workload

    Once traffic grows, keep the API thin and scale worker pods independently. Use Deployments for always-on services and Jobs for bursty back-office processing.

    from kubernetes import client, config
    
    config.load_kube_config()
    
    apps_v1 = client.AppsV1Api()
    
    deployment = client.V1Deployment(
        metadata=client.V1ObjectMeta(name="lending-worker"),
        spec=client.V1DeploymentSpec(
            replicas=3,
            selector=client.V1LabelSelector(match_labels={"app": "lending-worker"}),
            template=client.V1PodTemplateSpec(
                metadata=client.V1ObjectMeta(labels={"app": "lending-worker"}),
                spec=client.V1PodSpec(
                    containers=[
                        client.V1Container(
                            name="worker",
                            image="ghcr.io/your-org/lending-worker:latest",
                            ports=[client.V1ContainerPort(container_port=8000)],
                        )
                    ]
                ),
            ),
        ),
    )
    
    apps_v1.create_namespaced_deployment(namespace="ai-agents", body=deployment)
    

Testing the Integration

Run the graph locally first, then verify Kubernetes can create the workload in-cluster.

test_payload = {
    "applicant_id": "test_001",
    "income": 150000,
    "debt": 10000,
    "score": 0,
    "decision": "review",
}

result = lending_graph.invoke(test_payload)
print(result)

assert result["decision"] == "approve"
assert result["score"] == 850

Expected output:

{'applicant_id': 'test_001', 'income': 150000, 'debt': 10000, 'score': 850, 'decision': 'approve'}

If you want to verify Kubernetes too:

from kubernetes import client, config

config.load_kube_config()
core_v1 = client.CoreV1Api()

pods = core_v1.list_namespaced_pod(namespace="ai-agents", label_selector="app=lending-worker")
print([pod.metadata.name for pod in pods.items])

Real-World Use Cases

  • Loan prequalification pipeline

    • Use LangGraph to orchestrate document checks, income validation, and score calculation.
    • Run each stage in Kubernetes so you can isolate failures and scale by tenant or product line.
  • Human-in-the-loop underwriting

    • Route borderline cases to a review queue when LangGraph returns "review".
    • Use Kubernetes Jobs to process review batches and keep audit trails per namespace.
  • Multi-product credit ops

    • Run separate graphs for personal loans, SME lending, and BNPL.
    • Deploy each graph as its own service in Kubernetes with different resource limits and rollout policies.

The production pattern here is not complicated. Keep LangGraph focused on workflow logic, keep Kubernetes focused on execution boundaries, and connect them with small APIs or Jobs instead of trying to make one tool do both jobs.


Keep learning

By Cyprian Aarons, AI Consultant at Topiax.

Want the complete 8-step roadmap?

Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.

Get the Starter Kit

Related Guides