SuperAPI AI Directory

django-recommender-search-backend-patterns

Coding & development

View repository

Updated 10-16 03:46

About this skill

Experimental Django Recommender + Search Backend Best Practices

Implementation patterns for a Django backend serving mixed-results recommendations (Personalize / Databricks / microservice fan-out) and OpenSearch-backed search/feeds. 48 rules across 8 categories, ordered by execution lifecycle impact — earlier categories cascade through everything downstream.

This is the backend peer of the react-fetch-cache-patterns skill. React handles client-side waterfalls and caching; this skill handles server-side fan-out, downstream protection, OpenSearch query design, and ML-blend orchestration.

When to Apply

  • Building or reviewing Django views that fan out to AWS Personalize, Databricks Model Serving, internal microservices, or any ML inference downstream
  • Designing OpenSearch query endpoints (search results, infinite feeds, faceted search)
  • Implementing a recommendations endpoint that blends multiple ranker outputs
  • Investigating "Django backend slow when downstream is degraded" or "Personalize quota exhausted"
  • Adding caching, retry, circuit breakers, or rate limiting to outbound calls
  • Choosing between sync and async Django views, configuring uvicorn vs gunicorn
  • Designing DRF response shapes for paginated feeds, partial results, or degraded paths

Rule Categories by Priority

# Category Impact Prefix Rules
1 Fan-out Orchestration CRITICAL orch- 8
2 External Service Protection CRITICAL protect- 7
3 OpenSearch Query Patterns CRITICAL search- 8
4 Result Blending & Personalization HIGH blend- 5
5 Caching Strategy HIGH cache- 5
6 Resilience & Partial Results HIGH resilience- 5
7 Async & Concurrency MEDIUM-HIGH async- 5
8 API Response Design MEDIUM api- 5

Quick Reference

1. Fan-out Orchestration (CRITICAL)

2. External Service Protection (CRITICAL)

3. OpenSearch Query Patterns (CRITICAL)

4. Result Blending & Personalization (HIGH)

5. Caching Strategy (HIGH)

6. Resilience & Partial Results (HIGH)

7. Async & Concurrency (MEDIUM-HIGH)

8. API Response Design (MEDIUM)

How to Use

  1. Open references/_sections.md for category definitions and impact rationale
  2. Read individual rule files for incorrect-vs-correct code examples (each ~150-300 lines with Python code)
  3. For ready-to-use scaffolds, see scaffolding templates
  4. The AGENTS.md navigation document (auto-generated) provides a TOC for browsing

Scaffolding Templates

Five ready-to-adapt Python templates under assets/templates/:

Template Purpose
fanout_recommender_service.py.template Async fan-out client to Personalize/Databricks/microservice with per-downstream circuit breaker, bounded timeout, partial-result return
opensearch_search_view.py.template DRF view + OpenSearch search_after cursor + function_score blending + _source filtering
result_blender.py.template Score normalization + MMR diversity + canonical-ID dedup + cold-start fallback
redis_cache_with_stampede.py.template Stampede-safe cached function decorator with SETNX lock and jittered TTL
degraded_response.py.template Partial-results envelope with per-source status flags + tier-based fallback

Reference Files

File Description
references/_sections.md Category definitions, ordering, impact rationale, tier definitions
assets/templates/_template.md Template for authoring new rules
metadata.json Version, references, abstract

Related Skills

  • react-fetch-cache-patterns — Client-side peer covering React data fetching/caching (Suspense, query libraries, prefetch)
  • io-bound-data-processing — Python async patterns for batch and pipeline workloads
  • inngest-nextjs-patterns — Workflow patterns for server-side step functions