Execute Perplexity major re-architecture and migration strategies with strangler fig pattern.
Use when migrating to or from Perplexity, performing major version upgrades,
or re-platforming existing integrations to Perplexity.
Trigger with phrases like "migrate perplexity", "perplexity migration",
"switch to perplexity", "perplexity replatform", "perplexity upgrade major".
Migrate from traditional search APIs (Google Custom Search, Bing, SerpAPI) or legacy LLMs to Perplexity Sonar. Key advantage: Perplexity combines search + LLM summarization in a single API call, replacing a multi-step pipeline.
// Compare results between old and new adapter
async function compareSearchResults(query: string): Promise<{
perplexity: SearchResult;
google: SearchResult;
citationOverlap: number;
}> {
const [perplexity, google] = await Promise.all([
new PerplexitySearchAdapter().search(query),
new GoogleSearchAdapter().search(query),
]);
// Check citation overlap (shared domains)
const pplxDomains = new Set(perplexity.citations.map((u) => new URL(u).hostname));
const googleDomains = new Set(google.citations.map((u) => new URL(u).hostname));
const overlap = [...pplxDomains].filter((d) => googleDomains.has(d)).length;
return {
perplexity,
google,
citationOverlap: overlap / Math.max(pplxDomains.size, 1),
};
}
Step 5: Simplify Post-Migration
// Before migration: 3-step pipeline
// 1. Google Custom Search API → raw results
// 2. Send results to LLM for summarization
// 3. Extract citations manually
// After migration: 1-step
async function search(query: string): Promise<{ answer: string; sources: string[] }> {
const client = new OpenAI({
apiKey: process.env.PERPLEXITY_API_KEY!,
baseURL: "https://api.perplexity.ai",
});
const response = await client.chat.completions.create({
model: "sonar",
messages: [{ role: "user", content: query }],
});
return {
answer: response.choices[0].message.content || "",
sources: (response as any).citations || [],
};
}
Rollback Plan
set -euo pipefail
# Instant rollback: set traffic to 0%
# kubectl set env deployment/search-app PERPLEXITY_TRAFFIC_PERCENT=0
# The adapter layer keeps both implementations live until decommissioned
Error Handling
Issue
Cause
Solution
Citation format differs
Google returns titles, Perplexity returns URLs
Normalize in adapter
No raw results
Perplexity returns synthesized answer
Use search_results field if available
Higher latency
Perplexity does search + synthesis
Expected; cache to compensate
Cost increase
Perplexity uses more tokens
Route simple queries to sonar, limit max_tokens
Output
Adapter layer abstracting search implementations
Feature-flagged traffic split for gradual migration