Skip to main content

Deployment Overview

Genkit flows are just functions that can be deployed anywhere you can run JavaScript, Go, or Python code. This guide covers the most common deployment patterns and platforms.

Deployment Options

Genkit applications can be deployed to:
PlatformBest ForLanguage Support
Firebase FunctionsFirebase ecosystem integration, managed scalingJavaScript/TypeScript
Google Cloud RunContainerized deployments, auto-scalingAll (JS, Go, Python)
Node.js PlatformsTraditional Node.js hosting (Vercel, Fly.io, AWS)JavaScript/TypeScript
Go DeploymentsHigh-performance standalone serversGo
Python DeploymentsFlask/FastAPI integration, ASGI serversPython

Architecture Patterns

1. Serverless Functions

Deploy individual flows as serverless functions that scale automatically:
┌─────────────────────────────────────────────┐
│  Client Application                         │
└─────────────┬───────────────────────────────┘


┌─────────────────────────────────────────────┐
│  Cloud Functions / Cloud Run                │
│  ┌─────────────┐  ┌─────────────┐          │
│  │  Flow 1     │  │  Flow 2     │          │
│  │  (endpoint) │  │  (endpoint) │          │
│  └─────────────┘  └─────────────┘          │
└─────────────────────────────────────────────┘


┌─────────────────────────────────────────────┐
│  AI Models (Gemini, Claude, etc.)           │
└─────────────────────────────────────────────┘
Pros:
  • Automatic scaling
  • Pay-per-use pricing
  • No server management
Cons:
  • Cold start latency
  • Runtime limitations (timeouts, memory)

2. Containerized Services

Package your entire application in a container for flexible deployment:
┌─────────────────────────────────────────────┐
│  Docker Container                           │
│  ┌───────────────────────────────────────┐  │
│  │  Express/Flask/Go Server              │  │
│  │  ┌──────┐ ┌──────┐ ┌──────┐          │  │
│  │  │Flow 1│ │Flow 2│ │Flow 3│          │  │
│  │  └──────┘ └──────┘ └──────┘          │  │
│  └───────────────────────────────────────┘  │
└─────────────────────────────────────────────┘
Pros:
  • Consistent environments
  • Full control over runtime
  • Can run anywhere (GCP, AWS, Kubernetes)
Cons:
  • More configuration required
  • Infrastructure management

3. Standalone Servers

Deploy a traditional HTTP server with all flows exposed as endpoints:
// Go example
mux := http.NewServeMux()
for _, flow := range genkit.ListFlows(g) {
    mux.HandleFunc("POST /"+flow.Name(), genkit.Handler(flow))
}
log.Fatal(http.ListenAndServe(":8080", mux))

Choosing a Platform

Use Firebase Functions When:

  • You’re already using Firebase (Auth, Firestore, etc.)
  • You want managed infrastructure
  • You need automatic scaling
  • You’re building with JavaScript/TypeScript

Use Cloud Run When:

  • You need containerized deployments
  • You want language flexibility (Go, Python, Node.js)
  • You need more control than Functions
  • You want pay-per-use serverless scaling

Use Node.js Platforms When:

  • You’re deploying to Vercel, Fly.io, or AWS
  • You need Express.js integration
  • You want full control over the server

Use Go Servers When:

  • You need maximum performance
  • You want minimal resource usage
  • You’re building high-throughput services

Use Python (Flask/FastAPI) When:

  • You’re integrating with Python ML pipelines
  • You prefer Flask or FastAPI
  • You need ASGI server features

General Best Practices

1. Environment Variables

Store API keys and secrets in environment variables, never in code:
// Don't hardcode
const ai = genkit({
  plugins: [googleAI({ apiKey: 'sk-...' })] // ❌ Never do this
});

// Use environment variables
const ai = genkit({
  plugins: [googleAI()] // ✅ Reads GEMINI_API_KEY from env
});

2. Health Checks

Add health check endpoints for load balancers:
app.get('/health', (req, res) => {
  res.status(200).json({ status: 'healthy' });
});

3. Timeouts and Resource Limits

Configure appropriate timeouts for AI operations:
// For Cloud Functions
export const myFlow = onCallGenkit(
  {
    timeoutSeconds: 540, // 9 minutes for long-running AI tasks
    memory: '1GiB',
  },
  flowDefinition
);

4. Error Handling

Implement proper error handling for production:
const myFlow = ai.defineFlow(
  { name: 'myFlow' },
  async (input) => {
    try {
      return await ai.generate({ prompt: input });
    } catch (error) {
      console.error('Generation failed:', error);
      throw new UserFacingError('INTERNAL', 'Failed to generate response');
    }
  }
);

5. Monitoring and Observability

Enable telemetry for production monitoring:
import { enableFirebaseTelemetry } from '@genkit-ai/firebase';

enableFirebaseTelemetry();

6. Authentication

Secure your endpoints with authentication:
import { withContextProvider } from '@genkit-ai/express';

function requireAuth(req) {
  const token = req.headers['authorization'];
  if (!isValid(token)) {
    throw new UserFacingError('UNAUTHENTICATED', 'Invalid token');
  }
  return { user: decodeToken(token) };
}

app.post('/flow', expressHandler(myFlow, { 
  contextProvider: requireAuth 
}));

Next Steps

Firebase Deployment

Deploy to Cloud Functions for Firebase

Cloud Run Deployment

Containerize and deploy to Google Cloud Run

Node.js Deployment

Deploy Express apps to any Node.js platform

Go Deployment

Build and deploy Go HTTP servers

Build docs developers (and LLMs) love