Agent Skills: Experimental Django Recommender + Search Backend Best Practices

Django backend patterns for recommendation services (AWS Personalize, Databricks Model Serving, internal microservices) and OpenSearch-backed search/feed endpoints. Covers fan-out orchestration (asyncio.gather, deadline propagation, partial results, async client reuse), external service protection (timeouts, circuit breakers, jittered retry, bulkheads, rate limits), OpenSearch query patterns (search_after, _source filtering, function_score, aliases, routing, bool.filter), result blending (score normalization, MMR, dedup, cold-start), Redis caching (stampede protection, model-versioned keys, two-tier, negative), resilience (partial-response envelope, stale-on-error, graceful degradation), async (sync_to_async, async ORM, uvicorn, contextvars, disconnect cancellation), and DRF response shape (cursor pagination, ETag, throttling). Use when building, reviewing, or refactoring such a Django backend. Triggers even without explicit "scale" cues. Includes 5 scaffolding templates.

UncategorizedID: pproenca/dot-skills/django-recommender-search-backend-patterns

Install this agent skill to your local

pnpm dlx add-skill https://github.com/pproenca/dot-skills/tree/HEAD/skills/.experimental/django-recommender-search-backend-patterns

Skill Files

Browse the full folder contents for django-recommender-search-backend-patterns.

Download Skill

Loading file tree…

skills/.experimental/django-recommender-search-backend-patterns/SKILL.md

Skill Metadata

Name
django-recommender-search-backend-patterns
Description
Django backend patterns for recommendation services (AWS Personalize, Databricks Model Serving, internal microservices) and OpenSearch-backed search/feed endpoints. Covers fan-out orchestration (asyncio.gather, deadline propagation, partial results, async client reuse), external service protection (timeouts, circuit breakers, jittered retry, bulkheads, rate limits), OpenSearch query patterns (search_after, _source filtering, function_score, aliases, routing, bool.filter), result blending (score normalization, MMR, dedup, cold-start), Redis caching (stampede protection, model-versioned keys, two-tier, negative), resilience (partial-response envelope, stale-on-error, graceful degradation), async (sync_to_async, async ORM, uvicorn, contextvars, disconnect cancellation), and DRF response shape (cursor pagination, ETag, throttling). Use when building, reviewing, or refactoring such a Django backend. Triggers even without explicit "scale" cues. Includes 5 scaffolding templates.

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