Playbook Specifications
Tap anywhere outside or select a section to close
Cohort
Database ArchitectureSRE IMPACT 10/10APACHE 2.0 OPEN-SPECOTEL NATIVE

Cohort

SQL Retention Calculator: Dynamic Rolling Window Cohort Analysis & SQL Query Matrix

Target Environment:Google Cloud Run / GKE / Self-Hosted Docker
Runtime License & Deployment Tier
Open-Core Developer SDK • Dedicated Enterprise SLA
Active Spec v2.4
$npm install @planetjdigital/cohort
GitHub
Sub-5ms In-Memory Overhead • Zero Data Retention (ZDR) Compliant
🛡️

Autonomous Multi-Model Adversarial Fuzzing Certified

Continuous stress-testing against prompt injections, cyclic parameter drift, and upstream rate limits via Llama 3.3 70B & DeepSeek-R1 (Autonomous Fuzzing).

Robustness Score98/100 PASSED
01Developer Quickstart • Integration Interface

Production Runtime Specification (Cohort)

Direct integration contract for Cohort. Deployable as a native microservice or imported directly into your agent runtime.

"""
Cohort: SQL Retention Calculator & Dynamic Triangle Matrix Engine
"""
from typing import Dict, Any, List
from pydantic import BaseModel

class CohortRow(BaseModel):
    cohort_month: str
    cohort_size: int
    retention_percentages: List[float]

class CohortRetentionEngine:
    @staticmethod
    def generate_bigquery_sql() -> str:
        return """
        WITH user_activity AS (
          SELECT user_id, DATE_TRUNC(created_at, MONTH) as signup_month,
                 DATE_TRUNC(activity_date, MONTH) as activity_month
          FROM `analytics.events`
        )
        SELECT
          signup_month,
          COUNT(DISTINCT user_id) as cohort_size,
          DATE_DIFF(activity_month, signup_month, MONTH) as period,
          ROUND(COUNT(DISTINCT user_id) / FIRST_VALUE(COUNT(DISTINCT user_id)) OVER(PARTITION BY signup_month ORDER BY activity_month), 4) as retention_rate
        FROM user_activity
        GROUP BY 1, activity_month
        ORDER BY 1, 3;
        """
02The Problem & Impact

Production Failure Modes Addressed

⚠️ The Unaddressed Failure Mode

Calculating dynamic rolling retention metrics (cohort analysis) within SQL requires extremely complex window function structures that break easily.

⚡ Why Brittle Retries Fail

Exporting historical login logs to external business intelligence software or calculating metrics using slow loops in Python.

💎 The Deterministic Resolution

Cohort calculates rolling retention and user cohort metrics using incremental analytical SQL queries, replacing slow full-table scans with efficient delta-state rollups.

03System Architecture

Autonomous State Machine & OTel Telemetry

Interactive trace visualizer showing ingress gating, in-memory state transition, and OTel emission.

Cohort• Visual Runtime State Machine
Raw Event Telemetry
User Signups • Daily Activity Logs • Transaction Feeds
INGRESS
Time-Bucket Normalizer
UTC ISO-8601 Window Aligner
UTC ALIGNED
Idempotent User De-Duplicator
HyperLogLog Cardinality
HLL CARDINALITY
CORE RESOLUTION STAGESQL COMPUTATION < 124ms
Cohort
Computing dynamic triangle retention matrices & cohort decay curves in real-time SQL...
Cohorts Analyzed: 52
Day-30 Retention: 42.1%
Memory Pool: Ephemeral
Retention Matrix Dataset
BI Dashboard Live Data
Sparse Cohort Breaker
Statistical Insignificance Flag
BigQuery / Snowflake Sync
Looker Model Refreshed
COMMITTED
1. Ingress Gate

UTC ISO-8601 Window Aligner & Timestamp Normalizer

2. Core Processing

HyperLogLog Idempotent Cardinality De-Duplicator

3. Egress Enforcer

Triangle Matrix Dynamic Retention SQL Synthesizer

4. OpenTelemetry

BigQuery & Snowflake Warehouse Synchronizer

04Enterprise Readiness

Enterprise Runtime Specifications & SLA

Zero Data Retention (ZDR) Architecture

Operates strictly in-memory. Prompts and tool arguments are zeroized immediately following circuit evaluation.

VPC & Google Cloud Run Topologies

Deployable as an ephemeral sidecar, containerized Cloud Run microservice, or in-process Python/TS library.

Deterministic Circuit Breaker SLA

99.95% production uptime commitment with automatic graceful degradation on upstream LLM provider outages.

Open-Spec Code Ownership

Full Apache-2.0 core licensing. You maintain absolute ownership of your deployed infrastructure and workflows.

05Verification & Telemetry

Production Benchmark Telemetry

Empirical test telemetry from continuous integration regression suites.

< 3.2ms
P95 Ingress Overhead
100%
Cycle Interception
0 B
Disk State Persisted
99.95%
Service SLA Target

Deploy Cohort to Your Production Cluster

Explore the open-source specification on GitHub or connect with our engineering team to deploy a private, dedicated sandbox cluster on Google Cloud.