βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Render Web βββββΆβ Managed Kafka βββββΆβ Your Trading β
β Service β β (Upstash/ β β Application β
β β β CloudKarafka) β β β
β β’ Auto-scaling β β β β β’ Same code as β
β β’ Load balancer β β β’ High availabilityβ β local β
β β’ SSL/HTTPS β β β’ Auto-scaling β β β’ Auto-restart β
β β’ Git deploy β β β’ Monitoring β β β’ Environment β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
# 1. Go to https://upstash.com
# 2. Sign up with GitHub/Google
# 3. Create Kafka cluster (select region close to your users)
# 4. Copy connection details:
Bootstrap Server: tops-stingray-12345-us1-kafka.upstash.io:9092
Username: dG9wcy1zdGluZ3JheS0xMjM0NSQ...
Password: your-secure-password
SASL Mechanism: SCRAM-SHA-256
Security Protocol: SASL_SSL# 1. Go to https://cloudkarafka.com
# 2. Create account
# 3. Create instance (FREE tier: 25MB storage)
# 4. Get connection URL from consoleIn your Render service dashboard β Environment tab:
# Kafka Configuration (Required)
KAFKA_BOOTSTRAP_SERVERS=tops-stingray-12345-us1-kafka.upstash.io:9092
KAFKA_SASL_USERNAME=dG9wcy1zdGluZ3JheS0xMjM0NSQ...
KAFKA_SASL_PASSWORD=your-secure-password
KAFKA_SASL_MECHANISM=SCRAM-SHA-256
KAFKA_SECURITY_PROTOCOL=SASL_SSL
# Application Settings
KAFKA_CLIENT_ID=trading_app_prod
ENVIRONMENT=production
# Database & Other Services
DATABASE_URL=[Auto-generated by Render]
REDIS_URL=[If using Redis addon]
# Trading API Keys
UPSTOX_API_KEY=your-api-key
UPSTOX_API_SECRET=your-api-secret
# ... other broker APIs
# Security
JWT_SECRET_KEY=your-production-secret
DEBUG=false
LOG_LEVEL=INFO# 1. Push your code to GitHub
git add .
git commit -m "Production deployment ready"
git push origin main
# 2. In Render dashboard:
# - Connect to your GitHub repository
# - Select branch: main
# - Build command: pip install -r requirements.txt
# - Start command: python app.py
# 3. Render automatically deploys on every push# 1. Install Render CLI
npm install -g @render/cli
# 2. Deploy from local machine
render deploy# In Render dashboard β Logs tab, you should see:
β
Kafka config loaded: tops-stingray-12345-us1-kafka.upstash.io:9092
β
Created topic: trading.market_data.raw
β
Created topic: trading.market_data.processed
β
Kafka producer initialized
β
Started consumer: market_data_processor
π Trading application started successfully# Add this health check endpoint to your app.py:
from services.simple_kafka_system import get_kafka_system
@app.get("/health/kafka")
async def kafka_health():
kafka_system = get_kafka_system()
health = await kafka_system.health_check()
return health
# Visit: https://your-app.onrender.com/health/kafka
# Should return:
{
"kafka_connected": true,
"producer_ready": true,
"active_consumers": 3,
"system_running": true,
"topics_available": 8
}- Upstash Console: View message throughput, consumer lag, error rates
- CloudKarafka Dashboard: Monitor cluster health, topic statistics
- Logs: Real-time application logs
- Metrics: CPU, memory, response time
- Alerts: Set up notifications for errors/downtime
# Add comprehensive health check
@app.get("/health")
async def full_health_check():
kafka_system = get_kafka_system()
health = {
"status": "healthy",
"timestamp": int(time.time() * 1000),
"kafka": await kafka_system.health_check(),
"database": check_database_connection(),
"redis": check_redis_connection() if redis_enabled else "disabled",
"websocket": check_websocket_connections()
}
# Overall status
if not health["kafka"]["kafka_connected"]:
health["status"] = "unhealthy"
return health# render.yaml (optional)
services:
- type: web
name: trading-app
env: python
plan: starter # or professional for higher resources
region: oregon # choose region close to your users
buildCommand: "pip install -r requirements.txt"
startCommand: "python app.py"
healthCheckPath: "/health"
envVars:
- key: KAFKA_BOOTSTRAP_SERVERS
value: tops-stingray-12345-us1-kafka.upstash.io:9092
- key: KAFKA_SASL_USERNAME
value: your-username
# ... other env vars# In simple_kafka_config.py, adjust for production load:
class TradingKafkaTopics:
def __init__(self):
# Increase partitions for production load
self.topics = [
SimpleTopic("trading.market_data.raw", partitions=3, replication_factor=3),
SimpleTopic("trading.market_data.processed", partitions=6, replication_factor=3),
SimpleTopic("trading.signals.breakout", partitions=4, replication_factor=2),
SimpleTopic("trading.ui.price_updates", partitions=8, replication_factor=2),
# ... other topics
]- Free Tier: 10,000 messages/day
- Pay-as-you-go: $0.2 per 100K messages
- Pro Plan: $20/month for 10M messages
- Starter Plan: $7/month (512MB RAM, 0.5 CPU)
- Professional Plan: $25/month (2GB RAM, 1 CPU)
- Development/Small App: $7 (Render) + $0 (Upstash free) = $7/month
- Production App: $25 (Render) + $20 (Upstash) = $45/month
# Check environment variables in Render dashboard
# Verify managed Kafka service is running
# Check service region proximity# Verify username/password from Kafka provider
# Check SASL mechanism (usually SCRAM-SHA-256)
# Ensure Security Protocol is SASL_SSL# Check Render logs for specific error
# Verify all environment variables are set
# Test Kafka connection using health endpoint# Choose Kafka region close to Render region
# Increase Render plan (more CPU/RAM)
# Optimize Kafka consumer batch sizes- Created managed Kafka service (Upstash/CloudKarafka)
- Configured Render environment variables
- Set up GitHub integration for auto-deploy
- Added health check endpoints
- Configured monitoring/alerts
- Tested application functionality
- Verified Kafka message flow
- Set up backup/disaster recovery plan
Your production deployment is now ready! π