| name | deepgram-reference-architecture |
| description | Implement Deepgram reference architecture for scalable transcription systems.
Use when designing transcription pipelines, building production architectures,
or planning Deepgram integration at scale.
Trigger with phrases like "deepgram architecture", "transcription pipeline",
"deepgram system design", "deepgram at scale", "enterprise deepgram".
|
| allowed-tools | Read, Write, Edit, Bash(gh:*), Bash(curl:*) |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
Deepgram Reference Architecture
Overview
Reference architectures for building scalable, production-ready transcription systems with Deepgram.
Architecture Patterns
1. Synchronous API
Direct API calls for small files and low latency requirements.
2. Asynchronous Queue
Queue-based processing for batch workloads.
3. Real-time Streaming
WebSocket-based live transcription.
4. Hybrid Architecture
Combination of patterns for different use cases.
Pattern 1: Synchronous API Architecture
+----------+ +------------+ +----------+
| Client | --> | API Server | --> | Deepgram |
+----------+ +------------+ +----------+
|
v
+-----------+
| Database |
+-----------+
Best for:
- Short audio files (<60 seconds)
- Low latency requirements
- Simple integration
Implementation
import express from 'express';
import { createClient } from '@deepgram/sdk';
import { db } from './database';
const app = express();
const deepgram = createClient(process.env.DEEPGRAM_API_KEY!);
app.post('/transcribe', async (req, res) => {
const { audioUrl, userId } = req.body;
try {
const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
{ url: audioUrl },
{ model: 'nova-2', smart_format: true }
);
if (error) throw error;
const transcript = result.results.channels[0].alternatives[0].transcript;
await db.transcripts.create({
userId,
audioUrl,
transcript,
metadata: result.metadata,
});
res.json({ transcript, requestId: result.. });
} (err) {
res.().({ : });
}
});
Pattern 2: Asynchronous Queue Architecture
+----------+ +-------+ +--------+ +----------+
| Client | --> | Queue | --> | Worker | --> | Deepgram |
+----------+ +-------+ +--------+ +----------+
^ |
| v
| +-----------+
+----------------------| Database |
(poll/webhook) +-----------+
Best for:
- Long audio files
- Batch processing
- High throughput
Implementation
import { Queue } from 'bullmq';
import { v4 as uuidv4 } from 'uuid';
import { redis } from './redis';
const transcriptionQueue = new Queue('transcription', {
connection: redis,
});
export async function submitTranscription(
audioUrl: string,
options: { priority?: number; userId?: string } = {}
): Promise<string> {
const jobId = uuidv4();
await transcriptionQueue.add(
'transcribe',
{ audioUrl, userId: options.userId },
{
jobId,
priority: options.priority ?? 0,
attempts: 3,
backoff: {
type: 'exponential',
delay: 5000,
},
}
);
return jobId;
}
import { Worker, Job } ;
{ createClient } ;
{ db } ;
{ notifyClient } ;
deepgram = (process..!);
worker = (
,
(: ) => {
{ audioUrl, userId } = job.;
{ result, error } = deepgram...(
{ : audioUrl },
{ : , : }
);
(error) error;
transcript = result..[].[].;
db..({
: job.,
userId,
audioUrl,
transcript,
: result.,
});
(userId, {
: job.,
: ,
transcript,
});
{ transcript };
},
{
: redis,
: ,
}
);
worker.(, {
.();
});
worker.(, {
.(, error);
});
Pattern 3: Real-time Streaming Architecture
+----------+ +-----------+ +----------+
| Client | <-> | WebSocket | <-> | Deepgram |
+----------+ | Server | | Live |
+-----------+ +----------+
|
v
+-----------+
| Storage |
+-----------+
Best for:
- Live transcription
- Voice interfaces
- Real-time applications
Implementation
import { WebSocketServer, WebSocket } from 'ws';
import { createClient, LiveTranscriptionEvents } from '@deepgram/sdk';
const wss = new WebSocketServer({ port: 8080 });
const deepgram = createClient(process.env.DEEPGRAM_API_KEY!);
wss.on('connection', (clientWs: WebSocket) => {
console.log('Client connected');
const dgConnection = deepgram.listen.live({
model: 'nova-2',
smart_format: true,
interim_results: true,
});
dgConnection.on(LiveTranscriptionEvents.Open, () => {
console.log('Deepgram connected');
});
dgConnection.on(LiveTranscriptionEvents.Transcript, (data) => {
clientWs.(.({
: ,
: data..[].,
: data.,
}));
});
dgConnection.(., {
clientWs.(.({
: ,
: error.,
}));
});
clientWs.(, {
dgConnection.(data);
});
clientWs.(, {
dgConnection.();
.();
});
});
Pattern 4: Hybrid Architecture
+---------------+
+--> | Sync Handler | --> Deepgram
| +---------------+
+----------+ +-------+ |
| Client | --> | Router | | +---------------+
+----------+ +-------+ +--> | Async Queue | --> Worker --> Deepgram
| +---------------+
|
| +---------------+
+--> | Stream Handler| <-> Deepgram Live
+---------------+
Implementation
import express from 'express';
import { syncHandler } from './handlers/sync';
import { asyncHandler } from './handlers/async';
import { streamHandler } from './handlers/stream';
const app = express();
app.post('/transcribe', async (req, res) => {
const { audioUrl, mode, audioDuration } = req.body;
let selectedMode = mode;
if (!selectedMode) {
if (audioDuration && audioDuration < 60) {
selectedMode = 'sync';
} else if (audioDuration && audioDuration > 300) {
selectedMode = 'async';
} else {
selectedMode = 'sync';
}
}
switch (selectedMode) {
case 'sync':
return syncHandler(req, res);
case 'async':
return asyncHandler(req, res);
case 'stream':
return streamHandler(req, res);
:
(req, res);
}
});
Enterprise Architecture
+------------------+
| Load Balancer |
+------------------+
|
+-------------------------------+-------------------------------+
| | |
+---------------+ +---------------+ +---------------+
| API Server | | API Server | | API Server |
| (Region A) | | (Region B) | | (Region C) |
+---------------+ +---------------+ +---------------+
| | |
v v v
+---------------+ +---------------+ +---------------+
| Redis Cluster |<------------->| Redis Cluster |<------------->| Redis Cluster |
+---------------+ +---------------+ +---------------+
| | |
v v v
+---------------+ +---------------+ +---------------+
| Worker Pool | | Worker Pool | | Worker Pool |
+---------------+ +---------------+ +---------------+
| | |
+-------------------------------+-------------------------------+
|
+------------------+
| Deepgram API |
+------------------+
Enterprise Implementation
export const config = {
regions: ['us-east-1', 'us-west-2', 'eu-west-1'],
redis: {
cluster: true,
nodes: [
{ host: 'redis-us-east.example.com', port: 6379 },
{ host: 'redis-us-west.example.com', port: 6379 },
{ host: 'redis-eu-west.example.com', port: 6379 },
],
},
workers: {
concurrency: 20,
maxRetries: 5,
},
rateLimit: {
maxRequestsPerMinute: 1000,
maxConcurrent: 100,
},
monitoring: {
metricsEndpoint: '/metrics',
healthEndpoint: '/health',
tracingEnabled: true,
},
};
import { Router } from 'express';
import { getHealthyRegion } from './health';
import { forwardRequest } from './proxy';
const router = ();
router.(, (req, res) => {
region = ();
(!region) {
res.().({ : });
}
(req, res, region);
});
router;
Monitoring Architecture
import { Registry, collectDefaultMetrics, Counter, Histogram, Gauge } from 'prom-client';
export const registry = new Registry();
collectDefaultMetrics({ register: registry });
export const requestsTotal = new Counter({
name: 'transcription_requests_total',
help: 'Total transcription requests',
labelNames: ['status', 'model', 'region'],
registers: [registry],
});
export const latencyHistogram = new Histogram({
name: 'transcription_latency_seconds',
help: 'Transcription latency',
labelNames: ['model'],
buckets: [0.5, 1, 2, 5, 10, 30, 60, 120],
registers: [registry],
});
export const queueDepth = new Gauge({
: ,
: ,
: [registry],
});
activeConnections = ({
: ,
: ,
: [registry],
});
Resources
Next Steps
Proceed to deepgram-multi-env-setup for multi-environment configuration.