<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ahmed Salman Noor on Medium]]></title>
        <description><![CDATA[Stories by Ahmed Salman Noor on Medium]]></description>
        <link>https://medium.com/@ahmed.salman.noor?source=rss-228d10d11315------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Wlm0FOs0OT-hO6jN.</url>
            <title>Stories by Ahmed Salman Noor on Medium</title>
            <link>https://medium.com/@ahmed.salman.noor?source=rss-228d10d11315------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 02:11:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ahmed.salman.noor/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Commercial Intelligence on Existing Pharma Infrastructure]]></title>
            <link>https://medium.com/@ahmed.salman.noor/building-commercial-intelligence-on-existing-pharma-infrastructure-8c6c8a68f5b2?source=rss-228d10d11315------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c6c8a68f5b2</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[specialty-pharmacy]]></category>
            <category><![CDATA[pharma-commercial-ops]]></category>
            <dc:creator><![CDATA[Ahmed Salman Noor]]></dc:creator>
            <pubDate>Thu, 07 May 2026 16:36:38 GMT</pubDate>
            <atom:updated>2026-05-08T11:18:48.723Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s2kSQ8sKmXGcN6hhecSSNg.png" /></figure><p>The reason your commercial dashboard shows the wrong number is not your BI tool.</p><p>It’s row 847 of the SP flat file where one person entered the NPI in one format, and the SP entered it in another. That upstream mismatch is now inside your pull-through metric, your territory performance report, and your monthly KPI deck presented to leadership.</p><p>This is the actual state of commercial data operations inside most specialty pharma organizations today. Not a technology problem. A sequencing problem.</p><p>The industry conversation around AI in pharma commercial ops is evolving and usefully so. The most credible voices are no longer asking “which platform?” They’re asking something more operationally precise: what is the smallest, highest-leverage step you can take on the infrastructure you already own?</p><p>We’ve delivered inside this exact environment.</p><p>A specialty pharma client came to us after a seven-figure platform implementation that never reached production. Their data was already in Salesforce Health Cloud. SP dispense files were arriving weekly. The hub was adjudicating PA approvals in a separate system. The commercial ops team was reconciling everything manually in Excel, every Monday morning, for a leadership review that happened on Tuesday and was largely forgotten by Wednesday.</p><p>We didn’t propose a new platform.</p><p>We mapped what they had. We built a normalized SP/HUB data pipeline validating NPI records against CMS reference data, deduplicating patient records across the hub adjudication system, surfacing reconciliation exceptions before they reached reporting. We connected the output to their existing Salesforce environment and deployed an automated KPI layer.</p><p>Start-to-fill visibility. Abandonment trigger tracking. Pull-through rates by specialty pharmacy channel. PA denial root-cause analysis. Live.</p><p>Six weeks. No new platform licenses.</p><p>The transformation wasn’t technological. It was the decision to stop waiting for the perfect infrastructure and start activating the functional one.</p><p>Most specialty pharma commercial teams have the raw data. SP feeds. Salesforce activity data. IQVIA demand signals. Hub adjudication records. The gap is almost never the data itself. It is the activation layer the sequenced, use-case-anchored build that converts fragmented inputs into operational intelligence a commercial leader can act on Monday morning.</p><p>If your team cannot answer these questions from a live system today what is your current start-to-fill rate by SP, what drove last month’s abandonment spike, which territories have NPI record quality issues that is the gap worth addressing. Not in a five-year roadmap. In the next sprint.</p><p><em>Global IQ Services builds commercial data and AI systems for specialty pharma on the infrastructure you already own.</em></p><p>#PharmaAI #SpecialtyPharma #PharmaCommercialOps #PatientAccess</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c6c8a68f5b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Real Bottleneck in Pharma AI Isn’t the Model. It’s the Data Layer]]></title>
            <link>https://medium.com/@ahmed.salman.noor/the-real-bottleneck-in-pharma-ai-isnt-the-model-it-s-the-data-layer-b03794d67cc4?source=rss-228d10d11315------2</link>
            <guid isPermaLink="false">https://medium.com/p/b03794d67cc4</guid>
            <category><![CDATA[specialtypharma]]></category>
            <category><![CDATA[ai-pharma]]></category>
            <category><![CDATA[pharma-commercial-ops]]></category>
            <category><![CDATA[big-pharma]]></category>
            <dc:creator><![CDATA[Ahmed Salman Noor]]></dc:creator>
            <pubDate>Thu, 07 May 2026 16:24:12 GMT</pubDate>
            <atom:updated>2026-05-07T16:24:12.134Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xkqt8cfmK35atuP2F6cZcg.png" /></figure><p>Mankind Pharma just announced a company-wide integration of OpenAI Enterprise across field force, commercial operations, R&amp;D, and medical affairs.</p><p>It’s a landmark move. And the framing will be familiar to anyone who has sat in a pharma commercial ops leadership meeting for the last two years.</p><p>Here’s what the announcement doesn’t say and what we’ve consistently seen inside specialty pharma organizations trying to make this real:</p><p><strong>The field force AI problem is actually a data infrastructure problem.</strong></p><p>When AI-powered next-best-action systems fail to get adopted by field teams and most early deployments struggle well below 50% rep adoption the root cause is rarely the AI model.</p><p>It’s HCP data that hasn’t been validated in 18 months. It’s Rx signals arriving at T+7. It’s three data sources that have never been reconciled into a single commercial view.</p><p>AI agents don’t fail because the algorithm is wrong. They fail because the data foundation was never built to support them.</p><p><strong>The patient access funnel is the second gap nobody is talking about.</strong></p><p>Field force AI that drives better prescribing behavior means nothing if patients abandon between the HUB enrollment stage and first specialty pharmacy dispense. In complex specialty products rare disease, oncology supportive care, high-cost injectables that abandonment gap is where revenue and patient outcomes both collapse.</p><p>The start-to-first-fill funnel is still managed manually in most HUB operations teams we engage with. Prior auth triage, SP status reconciliation, benefit investigation all running on spreadsheets and shared inboxes while the commercial team invests in AI for the front of the funnel.</p><p><strong>What the Mankind announcement gets right:</strong></p><p>Institutionalizing AI is a leadership posture, not a technology purchase. The COO framing <em>“this is about building a more responsive, intelligent, future-ready enterprise”</em> is correct. The organizations that will win commercially in the next five years are the ones treating AI infrastructure as a strategic capability, not a departmental tool.</p><p>For US specialty pharma, that means solving the data architecture problem first. It means building the patient access intelligence layer, not just the field force layer. And it means deploying AI agents that are connected to real workflow — Salesforce, SP data feeds, HUB case management not just running on top of them.</p><p>The announcement layer and the ops layer are two different conversations.</p><p>We spend most of our time in the second one.</p><p><em>Curious what’s actually working in commercial AI deployment inside specialty pharma not at the announcement layer, but at the ops layer. What are you seeing?</em></p><p>#PharmaAI #SpecialtyPharma #PharmaCommercialOps #PatientAccess</p><p><em>— Global IQ Services | Intelligent Data &amp; AI Systems for Pharma</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b03794d67cc4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How JustAds Scales Micro Services with CI/CD, Terraform, Helm & ArgoCD on AWS]]></title>
            <link>https://medium.com/@ahmed.salman.noor/how-justads-scales-micro-services-with-ci-cd-terraform-helm-argocd-on-aws-18c13a98d207?source=rss-228d10d11315------2</link>
            <guid isPermaLink="false">https://medium.com/p/18c13a98d207</guid>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[gitops-for-micro-service]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[gitops-with-argocd]]></category>
            <dc:creator><![CDATA[Ahmed Salman Noor]]></dc:creator>
            <pubDate>Tue, 18 Nov 2025 17:30:21 GMT</pubDate>
            <atom:updated>2025-11-18T17:36:02.366Z</atom:updated>
            <content:encoded><![CDATA[<h3>How JustAds Scale Micro Services with CI/CD, Terraform, Helm &amp; ArgoCD on AWS</h3><p><em>By the CTO of JustAds (Ahmed Salman Noor) — a deep technical walkthrough from architecture, platform, and product perspectives</em></p><p>At JustAds we run dozens of Micro-Services in production across multiple environments. This post explains the design decisions and the concrete implementation we run for JustAds. A multi-repo GitOps model using GitHub Actions, Terraform, Helm, ArgoCD, and AWS (EKS + ECR + managed services). I will cover architecture, repo layout, infra, CI/CD flows, secrets, testing, progressive delivery, and how we promote from <strong><em>dev → staging → prod</em></strong>. Everything below is running in production at JustAds.</p><h3>Executive summary (CTO view — why this architecture)</h3><p>We needed three things simultaneously:</p><ul><li><strong>Autonomy for teams</strong> each Micro-Services must ship independently with its own tests, images, and pipelines so feature velocity is high.</li><li><strong>Centralized safety &amp; consistency</strong> platform-level policies, infra modules, and GitOps control plane must ensure environments are consistent, secure, and observable.</li><li><strong>Proven repeatability</strong> infrastructure, charts, and values must be auditable and reproducible from Git.</li></ul><p>We solved this by splitting responsibilities across repos (multi-repo), using Terraform modules for AWS infra, storing Helm values per environment, and letting ArgoCD ApplicationSet reconcile clusters from the platform-infra repo. GitHub Actions is the CI that builds, scans, pushes images to ECR and updates the platform repo (image tags). ArgoCD does the deploy.</p><h3>Platform infra repository (structure and intent)</h3><p>Here is the structure we use for the control plane:</p><pre>platform-infra-repo/<br>├── infrastructure/<br>│   ├── main.tf<br>│   ├── modules/<br>│   │   ├── eks/<br>│   │   ├── vpc/<br>│   │   ├── ecr/<br>│   │   ├── iam/<br>│   │   └── s3/<br>│   ├── envs/<br>│   │   ├── dev.tfvars<br>│   │   ├── staging.tfvars<br>│   │   └── prod.tfvars<br>│   └── backend.tf<br>├── environments/<br>│   ├── dev/<br>│   │   ├── values/<br>│   │   │   ├── user-service-values.yaml<br>│   │   │   ├── ad-delivery-values.yaml<br>│   │   │   └── frontend-values.yaml<br>│   │   └── argocd/apps/<br>│   ├── staging/<br>│   └── prod/<br>├── argocd/<br>│   ├── projects/<br>│   └── applicationset.yaml<br>└── .github/workflows/<br>    └── infra-deploy.yml</pre><p><strong>Why single platform repo?</strong><br> It centralizes environment definitions, Helm values per env, and ArgoCD configuration. Teams push image tag changes (only) to specific values files ArgoCD reconciles Kubernetes clusters.</p><h3>Terraform: remote state and module-driven infra</h3><p>We use Terraform modules for repeatable infra components (EKS, VPC, ECR, IAM, S3). Each environment has its own backend state stored in S3 with DynamoDB locks to prevent concurrent state corruption.</p><p>Example backend config:</p><pre>terraform {<br>  backend &quot;s3&quot; {<br>    bucket         = &quot;justads-terraform-state&quot;<br>    key            = &quot;envs/${var.environment}/terraform.tfstate&quot;<br>    region         = &quot;us-east-1&quot;<br>    dynamodb_table = &quot;justads-terraform-locks&quot;<br>    encrypt        = true<br>  }<br>}</pre><p><strong>Rationale:</strong></p><ul><li>State per environment isolates drift and accidental cross-environment changes.</li><li>Modules let us test and validate each primitive (e.g., EKS module) and reuse patterns safely.</li></ul><h3>Environment separation &amp; Helm values overrides</h3><p>Each environment has a directory with Helm values per service. Values are the only thing that changes per environment for deployments (image tag, replica counts, ingress hosts, resource requests/limits).</p><p>Example values file for staging:</p><pre># environments/staging/values/user-service-values.yaml<br>replicaCount: 3<br>image:<br>  repository: XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/user-service<br>  tag: v1.2.3-staging<br>resources:<br>  requests:<br>    cpu: &quot;100m&quot;<br>    memory: &quot;256Mi&quot;<br>  limits:<br>    cpu: &quot;500m&quot;<br>    memory: &quot;512Mi&quot;<br>ingress:<br>  host: user.staging.justads.x<br>config:<br>  LOG_LEVEL: INFO</pre><p><strong>Pattern:</strong> CI updates only the image.tag for the target environment. ArgoCD sees the change and deploys it automatically.</p><h3>ArgoCD + ApplicationSet automated GitOps orchestration</h3><p>We use ArgoCD to keep clusters in-sync with Git. To avoid copying many Application manifests we generate them dynamically with an ApplicationSet based on file discovery in environments/*/values/*-values.yaml.</p><p>Example applicationset.yaml (abridged):</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: ApplicationSet<br>metadata:<br>  name: justads-services<br>spec:<br>  generators:<br>    - git:<br>        repoURL: &#39;https://github.com/xxx/platform-infra-xxx&#39;<br>        revision: main<br>        directories:<br>          - path: &#39;environments/*/values/*-values.yaml&#39;<br>  template:<br>    metadata:<br>      name: &#39;{{path.basename}}-{{path.parentBasename}}&#39;<br>    spec:<br>      project: microservices<br>      source:<br>        repoURL: &#39;https://github.com/xxx/platform-infra-repo&#39;<br>        path: &#39;environments/{{path.parentBasename}}/charts/{{path.basename}}&#39;<br>        targetRevision: main<br>        helm:<br>          valueFiles:<br>            - &#39;../../values/{{path.basename}}-values.yaml&#39;<br>      destination:<br>        namespace: &#39;{{path.parentBasename}}&#39;<br>        server: https://kubernetes.default.svc<br>      syncPolicy:<br>        automated:<br>          prune: true<br>          selfHeal: true</pre><p><strong>Benefits:</strong></p><ul><li>One manifest generates per-service, per-env ArgoCD Applications.</li><li>prune removes orphaned resources; selfHeal repairs drift automatically.</li><li>ArgoCD becomes the single reconciliation plane no manual kubectl apply.</li></ul><h3>CI/CD pipeline: build, test, scan, push, deploy (pattern)</h3><p>Each service’s pipeline implements these stages:</p><ol><li><strong>Unit tests &amp; linting </strong>quick feedback on PRs/merges.</li><li><strong>Build image</strong> tag images using semver + short SHA / run number.</li><li><strong>Integration tests</strong> run against ephemeral infra or test clusters.</li><li><strong>Image scanning </strong>Trivy for vulnerabilities (block on critical).</li><li><strong>Push to ECR</strong> lifecycle policy keeps last N images.</li><li><strong>Update platform-infra values</strong> change image tag in environments/&lt;env&gt;/values/&lt;service&gt;-values.yaml and push.</li></ol><p>A simplified GitHub Actions snippet for the pipeline:</p><pre>name: CI/CD - User Service<br><br>on:<br>  push:<br>    branches: [ main ]<br><br>jobs:<br>  test:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - uses: actions/setup-python@v4<br>        with:<br>          python-version: &#39;3.11&#39;<br>      - run: pip install -r requirements.txt<br>      - run: pytest tests/unit -q<br><br>  build:<br>    needs: test<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - uses: aws-actions/configure-aws-credentials@v4<br>        with:<br>          aws-region: us-east-1<br>          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>      - uses: aws-actions/amazon-ecr-login@v2<br>      - run: |<br>          IMAGE_TAG=$(git describe --tags --always)-${GITHUB_RUN_NUMBER}<br>          docker build -t $ECR_REGISTRY/user-service:$IMAGE_TAG .<br>          docker push $ECR_REGISTRY/user-service:$IMAGE_TAG<br><br>  scan:<br>    needs: build<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: aquasecurity/trivy-action@v1<br>        with:<br>          image-ref: $ECR_REGISTRY/user-service:${{ needs.build.outputs.image_tag }}<br><br>  update-gitops:<br>    needs: [scan]<br>    runs-on: ubuntu-latest<br>    steps:<br>      - run: |<br>          git clone https://github.com/xxx/platform-infra-repo.git /tmp/platform<br>          cd /tmp/platform/environments/staging/values<br>          yq e &#39;.image.tag = &quot;&#39;&quot;${{ needs.build.outputs.image_tag }}&quot;&#39;&quot;&#39; -i user-service-values.yaml<br>          git add .<br>          git commit -m &quot;update: user-service -&gt; ${{ needs.build.outputs.image_tag }}&quot;<br>          git push</pre><p><strong>Notes:</strong></p><ul><li>CI only updates the Helm values file. ArgoCD is responsible for applying the change to the cluster.</li><li>We gate promotions with smoke tests and human approvals for production merges.</li></ul><h3>Security, versioning, and testing disciplines</h3><ul><li><strong>Image tagging</strong>: semantic versions (vX.Y.Z) for releases; CI appends SHAs/CI run numbers for traceability (e.g., v1.2.3-abcdef-1234).</li><li><strong>ECR lifecycle policy</strong>: keep last X images and always keep tags starting with v.</li><li><strong>Vulnerability scanning</strong>: Trivy on each build; fail pipeline on high/critical vulnerabilities.</li><li><strong>SAST &amp; dependency management</strong>: GitHub Advanced Security, Dependabot for deps, Bandit for Python SAST.</li><li><strong>Terraform testing</strong>: terraform validate + Terratest for integration tests on modules.</li><li><strong>Application tests</strong>: unit tests on every commit; integration tests on merge; smoke tests after staging deploy.</li></ul><h3>Secrets management SOPS + KMS + SealedSecrets + IRSA</h3><p>Secrets must be safe in Git and decrypted only by the platform at deployment:</p><ul><li>Store encrypted YAML in Git using sops with AWS KMS:</li></ul><pre>sops -e --kms &quot;arn:aws:kms:us-east-1:1234:key/...&quot; secrets.yaml &gt; secrets.enc.yaml</pre><ul><li>Use SealedSecrets with ArgoCD to securely store and apply secrets to clusters.</li><li>At runtime we prefer AWS managed secrets for application usage (Secrets Manager / Parameter Store) via IRSA: EKS service accounts get fine grained IAM roles for specific secrets access least privilege.</li><li>ArgoCD + sealed-secrets plugin handles decryption on the cluster side; cluster nodes never hold plaintext secrets in Git.</li></ul><p><strong>Why this combo?</strong> Encrypted-at-rest in Git, KMS controlled keys, no human-exposed secrets in pipelines, and principle of least privilege for the running pods.</p><h3>Progressive delivery: Argo Rollouts + Prometheus integration</h3><p>To reduce blast radius we use <strong>Argo Rollouts</strong> with canary strategies and tie them to Prometheus alerts/metrics.</p><p>Example canary rollout:</p><pre>apiVersion: argoproj.io/v1alpha1<br>kind: Rollout<br>metadata:<br>  name: user-service<br>spec:<br>  strategy:<br>    canary:<br>      steps:<br>        - setWeight: 10<br>        - pause: { duration: 1m }<br>        - setWeight: 50<br>        - pause: { duration: 5m }<br>        - setWeight: 100</pre><ul><li>Rollouts are wired to Prometheus alerts (error-rate, latency). If error-rate exceeds threshold, Argo Rollouts aborts and a rollback is triggered automatically.</li><li>We use feature flags and targeted traffic splitting where needed for experiments.</li></ul><h3>Observability &amp; alerting metrics, logs, traces</h3><p>We run a full observability stack:</p><ul><li><strong>Prometheus / Mimir</strong> for metrics (Mimir for long-term storage and scale)</li><li><strong>Grafana</strong> for dashboards and alerting front-end</li><li><strong>Loki</strong> for logs (structured JSON logs from services)</li><li><strong>Tempo</strong> for distributed traces</li></ul><h3>Final thoughts / Closure</h3><p>This stack Terraform modules for infra, Helm charts and per-env value files, GitHub Actions per-repo for CI, ArgoCD ApplicationSet for GitOps orchestration, and EKS/ECR on AWS gives JustAds a balance of autonomy and control. Teams can move fast because they own their code, tests, and charts.</p><p>If you’re adopting a similar approach, start small: one infra module, one service pipeline, one ApplicationSet generator. Then harden security, add progressive delivery, and roll out the pattern across teams. The combination of per-repo CI + centralized GitOps control plane has proven extremely effective for scale.</p><blockquote>If you are working similar challenges around Micro-Services, building out modern GitOps platforms, or just trying to keep your infra from turning into a giant ball of yarn, feel free to reach out me at <strong>ahmed.salman.noor@gmail.com</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18c13a98d207" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving the “Alpha Problem”: How We’re Keeping AI-Generated Characters Consistent Across Scenes]]></title>
            <link>https://medium.com/@ahmed.salman.noor/solving-the-alpha-problem-how-were-keeping-ai-generated-characters-consistent-across-scenes-4ebd690ac6a2?source=rss-228d10d11315------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ebd690ac6a2</guid>
            <category><![CDATA[ai-video-generator]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[prompt-engineering]]></category>
            <category><![CDATA[llm-statefullness]]></category>
            <category><![CDATA[visual-consistency]]></category>
            <dc:creator><![CDATA[Ahmed Salman Noor]]></dc:creator>
            <pubDate>Tue, 21 Oct 2025 21:31:01 GMT</pubDate>
            <atom:updated>2025-10-21T21:31:01.651Z</atom:updated>
            <content:encoded><![CDATA[<p><em>By Ahmed Lead Software Engineer (13+ years building intelligent content systems)</em></p><h3>The Hook: When AI Forgets Its Own Characters</h3><p>Imagine this:<br>You’re watching an AI-generated short film.</p><p><strong>Scene 1:</strong> our hero, <strong>Alpha</strong>, walks into a café.<br>Short hair. Blue jacket. Calm expression.</p><p><strong>Scene 4:</strong> Alpha reappears.<br>Long hair. Different jacket. Different face.</p><p>Same name. New person.<br>It’s like the AI version of <em>“Who are you again?”</em></p><p>That’s the <strong>Alpha Problem</strong> a surprisingly complex challenge that every team working on <strong>autonomous video generation</strong> eventually runs into.</p><h3>Why This Happens: Stateless AI Models</h3><p>This issue is not random. It’s baked into how today’s generative models work.</p><p>Most AI video or diffusion models are <strong>stateless</strong> they process each request as a one off, with no memory of previous outputs.</p><p>From a systems perspective:</p><blockquote><em>Each API call is an independent transaction with no memory of what came before.</em></blockquote><p>Let’s see what that looks like.</p><pre># Stateless behavior in practice<br>image_1 = diffusion_model.generate(&quot;a man named Alpha wearing a blue jacket&quot;)<br>image_2 = diffusion_model.generate(&quot;the same man, now sitting in a car&quot;)<br># Result: image_2 shows a DIFFERENT man.<br># The model has no idea what Alpha looked like in the first call.</pre><p>So unless we build <strong>statefulness</strong> into the pipeline a memory of who Alpha is visual continuity is doomed.</p><h3>Making the System “Stateful”</h3><p>To keep characters consistent across scenes, the pipeline needs to “remember” what each character looks like and reuse that knowledge later.</p><p>That state might include:</p><ul><li>Facial geometry and proportions</li><li>Hair color, skin tone, and body type</li><li>Emotional baseline or personality tone</li><li>Latent embedding (the mathematical “fingerprint” of their face)</li></ul><h3>Approach 1: Textual Anchoring (Prompt Reuse)</h3><p>The simplest fix is to use the same detailed description every time.</p><pre>alpha_desc = &quot;Alpha, a 35-year-old man with short brown hair, tan skin, and calm blue eyes&quot;<br>scene_1 = generate_scene(f&quot;{alpha_desc} walks into a cafe&quot;)<br>scene_4 = generate_scene(f&quot;{alpha_desc} drives away in his car&quot;)</pre><h3>Pros</h3><ul><li>Easy to implement</li><li>Works with any text-to-image or video model</li><li>No extra compute cost</li></ul><h3>Cons</h3><ul><li>Still visually unstable (diffusion randomness)</li><li>Subtle facial drift over time</li><li>No true continuity</li></ul><p><strong>Verdict:</strong> Great for demos, not for production.</p><h3>Approach 2: Reference Image Conditioning</h3><p>Next step generate a <strong>reference portrait</strong> of Alpha and feed it into future generations using <strong>ControlNet</strong> or <strong>IP-Adapter</strong>.</p><pre># Step 1: Create a base portrait<br>alpha_portrait = diffusion_model.generate(&quot;Alpha portrait, neutral expression&quot;)<br># Step 2: Reuse it as a reference<br>scene_2 = diffusion_model.generate(<br>    &quot;Alpha sitting in a car, same person as reference&quot;,<br>    image_condition=alpha_portrait<br>)</pre><pre>graph TD<br>A[Character Registry] --&gt; B[Portrait Reference]<br>B --&gt; C[ControlNet / IP-Adapter Generator]<br>C --&gt; D[Scene Output]</pre><h3>Pros</h3><ul><li>Much stronger visual consistency</li><li>Preserves facial features and tone</li><li>Fully automated</li></ul><h3>Cons</h3><ul><li>Adds small GPU overhead</li><li>Struggles with extreme lighting or poses</li></ul><p><strong>Verdict:</strong> Solid improvement ~90% visual consistency.</p><h3>Approach 3: Embedding Reuse (Character Memory)</h3><p>Here, we store a <strong>latent embedding</strong> a numeric vector that represents Alpha’s face.</p><pre># Step 1: Generate &amp; encode Alpha<br>alpha_image = diffusion_model.generate(&quot;Alpha portrait, calm face&quot;)<br>alpha_embedding = clip_model.encode_image(alpha_image)<br><br># Step 2: Reuse embedding later<br>scene_3 = generator.generate_with_embedding(<br>    prompt=&quot;Alpha running through the rain&quot;,<br>    embedding=alpha_embedding<br>)</pre><pre>graph TD<br>A[Scene Generator] --&gt; B[Character Registry]<br>B --&gt; C[Embedding Store (CLIP/Latent)]<br>C --&gt; D[Generator with Embedding Conditioning]</pre><h3>Pros</h3><ul><li>Reusable across videos</li><li>Excellent facial stability</li><li>Enables search (“find all Alpha scenes”)</li></ul><h3>Cons</h3><ul><li>Minor drift over time</li><li>Requires model-level embedding support</li></ul><p><strong>Verdict:</strong> Production-friendly scalable and precise (~92% match).</p><h3>Approach 4: Fine-Tuned Character Models (LoRA per Character)</h3><p>This approach fine-tunes a mini model (LoRA) for each character using a few generated frames.</p><pre>dataset = [face_crop1, face_crop2, face_crop3]<br>train_lora(&quot;Alpha_Model&quot;, dataset)<br>scene_5 = generator.generate(&quot;Alpha smiling&quot;, lora=&quot;Alpha_Model&quot;)</pre><h3>Pros</h3><ul><li>Perfect visual match</li><li>Works across lighting and expressions</li></ul><h3>Cons</h3><ul><li>10–30 mins training per character</li><li>Heavy GPU and storage cost</li></ul><p><strong>Verdict:</strong> Great for celebrity avatars.</p><h3>Approach 5: The Hybrid Solution (What We’re Using)</h3><p>After testing all of the above, the most scalable and reliable method is a <strong>Hybrid Embedding + Validation Loop</strong>.</p><p>Here’s how it works:</p><pre>graph TD<br>A[Scene 1] --&gt; B[Character Extractor]<br>B --&gt; C[Character Registry (portrait + embedding)]<br>C --&gt; D[Scene Generator with Conditioning]<br>D --&gt; E[CLIP Validator]<br>E --&gt;|Pass| F[Render Final]<br>E --&gt;|Fail| G[Regenerate Scene]</pre><h3>Step-by-Step:</h3><ol><li>Generate the first appearance of each character.</li><li>Extract a <strong>CLIP embedding</strong> + cropped <strong>portrait</strong>.</li><li>Store both in a <strong>Character Registry</strong>.</li><li>For each new scene → condition the generation on this data.</li><li>Validate with a <strong>CLIP similarity check</strong>.</li><li>If similarity &lt; 0.88 → regenerate automatically.</li></ol><h3>Simplified Implementation</h3><pre>registry = {}</pre><pre>def generate_character_scene(character, prompt):<br>    if character not in registry:<br>        img = generator.generate(prompt)<br>        embedding = clip.encode_image(img)<br>        registry[character] = {&quot;img&quot;: img, &quot;embedding&quot;: embedding}<br>        return img</pre><pre>    ref = registry[character]<br>    img = generator.generate_with_embedding(prompt, ref[&quot;embedding&quot;])<br>    sim = clip.compare(img, ref[&quot;embedding&quot;])</pre><pre>    if sim &lt; 0.88:<br>        print(f&quot;Regenerating {character} (similarity={sim})&quot;)<br>        return generate_character_scene(character, prompt)  # Retry<br>    return img</pre><p>This approach introduces <strong>statefulness</strong>, <strong>visual memory</strong>, and a <strong>feedback loop</strong> the three pillars of stable, automated video generation.</p><h3>Tradeoffs Summary</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xl9qubR35EJQnjl0_V_oUg.png" /></figure><h3>Final Thoughts</h3><p>When 80% of your characters are <em>new per video</em>, fine-tuning per character isn’t an option.</p><p>The <strong>hybrid model</strong> wins:</p><ul><li>No manual retraining</li><li>Fast inference</li><li>Auto-correction via CLIP similarity</li><li>Works even with diverse storylines</li></ul><p>You’ll still see about <strong>5% minor drift</strong>, we are working on improving this. Good thing is human eye won’t notice. Machines will.</p><p>That’s the sweet spot between <strong>scalability</strong>, <strong>speed</strong>, and <strong>continuity</strong>.</p><h3><em>If you’re working on AI-generated media, or facing similar consistency nightmares let’s connect at ahmed.salman.noor@gmail.com.</em></h3><p>👋 <strong>Follow me on Medium</strong> for more deep dives into system design and Gen-AI architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ebd690ac6a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>