<?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 Aiman Zaki on Medium]]></title>
        <description><![CDATA[Stories by Aiman Zaki on Medium]]></description>
        <link>https://medium.com/@aiman.zaki?source=rss-b714d8699b06------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*KzazBWF9P7OQzxXV</url>
            <title>Stories by Aiman Zaki on Medium</title>
            <link>https://medium.com/@aiman.zaki?source=rss-b714d8699b06------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 05:36:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aiman.zaki/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[Serverless, Secure, and GPU-Accelerated: How I “Kobe’d” an AI Model into Google Cloud]]></title>
            <link>https://medium.com/@aiman.zaki/serverless-secure-and-gpu-accelerated-how-i-kobed-an-ai-model-into-google-cloud-b85f7d041f99?source=rss-b714d8699b06------2</link>
            <guid isPermaLink="false">https://medium.com/p/b85f7d041f99</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[google-cloud-run]]></category>
            <category><![CDATA[gcp]]></category>
            <dc:creator><![CDATA[Aiman Zaki]]></dc:creator>
            <pubDate>Thu, 27 Nov 2025 17:49:29 GMT</pubDate>
            <atom:updated>2026-03-23T17:38:05.052Z</atom:updated>
            <content:encoded><![CDATA[<p>For my work I recently had to look at image compression. Specifically, using models like <a href="https://github.com/LuizScarlet/StableCodec"><strong>StableCodec</strong></a> to squeeze pixels into the smallest formats.</p><p>Researching these models is fun. But a model living in a localhost:8888 Jupyter Notebook is useless to the rest of the company. I didn&#39;t want to spend weeks configuring a Kubernetes cluster, setting up Node Pools, or debugging Helm charts just to show a demo.</p><p>I wanted to take this model, wrap it in FastAPI, and just <strong>“Kobe” it into the cloud.</strong> 🏀</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/0*buE93p1HVDzVP7a4.gif" /></figure><p><a href="http://sparc-frontend-667263174832.europe-west1.run.app/"><strong>👉 See the live demo running here</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NVw3CZKjnWoYZbznSv4jCg.gif" /></figure><p>The goal? Go from “Product Definition” to “Live GPU-Accelerated API” in a few days.</p><p>Here is how we built a Serverless AI pipeline on Google Cloud Run, the walls we hit, and why this is the fastest way to iterate on AI products.</p><h3>The Strategy: Speed &gt; Perfection</h3><p>We skipped the complex orchestration. We went full Serverless.</p><ul><li><strong>Infrastructure:</strong> Terraform (Everything as Code).</li><li><strong>Compute:</strong> Cloud Run Gen 2 (NVIDIA L4 GPUs).</li><li><strong>Container:</strong> A 20GB beast.</li></ul><p><strong>Wait, 20GB?</strong> Yes. In a perfect world, you mount weights from object storage at runtime to keep containers light. In a “Ship It” world, I baked the weights directly into the container image.</p><p><strong>Why?</strong> Because I’d rather wait 10 minutes for a build pipeline than have my user wait 5 minutes for a cold start while the container downloads 15GB of data. We are scaling to zero to save costs; when the container wakes up, it needs to be ready <em>now</em>.</p><h3>The Block: The “Internal” Trap 🛑</h3><p>I deployed the infrastructure using Terraform. I set the Backend to INGRESS_TRAFFIC_INTERNAL_ONLY because exposing a GPU API to the public internet is a great way to burn a hole in your credit card.</p><p>I took the shot. <strong>Airball.</strong></p><p>My Frontend (Next.js on Cloud Run) tried to call the Backend. <strong>Result:</strong> 404 Page Not Found (The Google HTML kind, not the JSON kind).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*SSTwPjL4jWk1fs0V5B33xw.png" /></figure><p><strong>The Realization:</strong> Just because two services are in the same Google Cloud project doesn’t mean they are on the same “network.” By default, my Frontend was going out to the public internet to try and call the Backend. The Backend saw a request coming from the wild, saw it wasn’t internal, and slammed the door.</p><h3>The Rebound: VPC Direct Egress 🔄</h3><p>I didn’t need to lower my security standards. I needed a tunnel. We used <strong>Direct VPC Egress</strong> in Terraform.</p><pre># The Frontend Service Configuration<br>vpc_access {<br>  network_interfaces {<br>    network    = &quot;default&quot;<br>    subnetwork = &quot;default&quot;<br>  }<br>  egress = &quot;ALL_TRAFFIC&quot;<br>}</pre><p>This forced the Frontend traffic through the private VPC pipe. Now, the Frontend acts like it’s inside the firewall. The Backend saw an internal IP, and the connection was established.</p><h3>The Assist: Zero-Trust Identity 🤝</h3><p>The network pipe was open, but we still needed authentication. We didn’t want to manage API keys.</p><p>We used <strong>Application Default Credentials (ADC)</strong>. The Frontend Service Account identifies itself to the Backend Service Account automatically.</p><pre>import { GoogleAuth } from &#39;google-auth-library&#39;;<br>const auth = new GoogleAuth();<br>// Get the specific ID token for the backend URL<br>const client = await auth.getIdTokenClient(process.env.BACKEND_URL);</pre><p>Nothing but net.</p><h3>The “Invisible” Foul: The BodyParser Trap 🚩</h3><p>The pipes were clean. Auth was passing. Network was routing. We sent an image. <strong>It broke.</strong></p><p>The backend returned 200 OK, but the resulting image was a corrupted mess.</p><p><strong>The Culprit:</strong> Next.js, trying to be helpful, was parsing our binary image stream as JSON/Text before proxying it. It was mangling the bytes.</p><p><strong>The Fix:</strong> We had to explicitly tell the framework to keep its hands off the data.</p><pre>// pages/api/decompress.js<br>export const config = {<br>  api: {<br>    bodyParser: false, // Vital for streaming binary to the GPU<br>  },<br>};</pre><p>This simple config change allowed the raw stream to flow directly from the user’s browser to the GPU memory.</p><h3>The Follow-through: Native A/B Testing 🧪</h3><p>Now that the pipeline is established, the real fun begins. Because we are on Cloud Run, we get <strong>Traffic Splitting</strong> for free.</p><p>We don’t need to build complex routing logic to test a new compression model or a new weight file.</p><ul><li>Deploy <strong>Revision-2</strong> with the new model.</li><li>Tell Cloud Run: “Send 10% of traffic to Rev-2, 90% to Rev-1.”</li><li>Monitor latency and quality.</li></ul><p>If the new model is trash, we revert instantly. If it’s better, we roll it out to 100%. We can iterate on the model logic without ever touching the infrastructure code again.</p><h3>Conclusion: Just Kobe It.</h3><p>This wasn’t just about image compression.</p><p>You can take this exact architecture — FastAPI, Docker, Terraform, Cloud Run — and swap out my model for yours. LLMs, Object Detection, Audio Transcribing; the pattern holds.</p><ul><li><strong>If you want to spend months building a platform, use Kubernetes.</strong></li><li><strong>If you want to ship a feature by Friday, just Kobe it.</strong></li></ul><p>Check out the full infrastructure and code here: <a href="https://github.com/devoteamgcloud/SPARC-web-compression/tree/dev"><strong>GitHub: SPARC-web-compression</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b85f7d041f99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lean, Mean, and Serverless: How I Built a $5-a-Day Data Ingestion Beast on GCP]]></title>
            <link>https://medium.com/@aiman.zaki/lean-mean-and-serverless-how-i-built-a-5-a-day-data-ingestion-beast-on-gcp-bf8409b01a08?source=rss-b714d8699b06------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf8409b01a08</guid>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Aiman Zaki]]></dc:creator>
            <pubDate>Mon, 17 Nov 2025 17:08:29 GMT</pubDate>
            <atom:updated>2025-11-18T09:43:10.755Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>Because who needs a 100-node Airflow cluster to move CSVs?</em></blockquote><h3>🧩 1. Introduction — The Quest for a Cheap, Fast, and Cool Data Platform</h3><p>Let’s be honest: most data ingestion systems are over-engineered monsters. They run 24/7, cost a small fortune, and break at 2 a.m. on Saturdays.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YcbbCXnlwilhjlpSB3LxRQ.png" /></figure><p>So, I asked myself a simple question:</p><blockquote><em>“What’s the cheapest, eazyest, most reliable way to load data into BigQuery?”</em></blockquote><p>Turns out, it’s right there in the CLI:</p><pre>bq load --source_format=CSV my_project:my_dataset.my_table \\<br>gs://my_bucket/my_table.csv name:STRING,age:INTEGER</pre><p>That’s it. That’s the hero of our story.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*IEDLnBXfEVKz7YgE.gif" /></figure><p>A one-liner so simple it hurts, but also the foundation of a lean and mean data ingestion framework that now handles <strong>50,000+ files on a peak day</strong> (bursting to <strong>5,000+ files per minute</strong>) on GCP.</p><h3>⚙️ 2. The “Lean” in Lean &amp; Mean — Serverless Spinach</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*sc8TrPq5gNK04qn0.gif" /></figure><p>The first design decision: <strong>no servers, no DAGs, no cron jobs.</strong> If something could be done by GCP natively, it should be.</p><p>We went 100% serverless and event-driven:</p><ol><li>A file lands in a Cloud Storage bucket.</li><li><strong>EventArc</strong> immediately spots the file and pushes an event <em>directly</em> into a <strong>Cloud Tasks</strong> queue. This is our shock absorber — a critical buffer that smooths out insane file bursts.</li><li>A <strong>Cloud Function</strong> (let’s call it file-loader) is configured as the HTTP target for the Cloud Tasks queue. Tasks feeds events to this function at a controlled, steady rate, protecting our downstream systems.</li></ol><p>No polling, no schedulers — just one file, one event, one task in a queue.</p><blockquote>🧠 Example: gs://my_bucket/my_file/my_dataset/my_table.csv → Load into my_project:my_dataset.my_table.</blockquote><p>This file-loader function is beautifully simple. Its only job is to parse the file path for the dataset/table name and execute the bq load command. We let BigQuery handle the <em>actual</em> validation. Why build a validation layer when the target system does it for free?</p><h3>⚡ 3. The “Mean” in Lean &amp; Mean — The Event-Driven Handoff</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/0*NG_M69paeWj3kaSM.gif" /></figure><p>This is where the platform gets “mean.” Handling 5k files a minute isn’t about the <em>first</em> function; it’s about what happens <em>after</em>.</p><p>The bq load job is <strong>asynchronous</strong>. Our file-loader function fires it off and finishes in milliseconds, long before the data is loaded. So how do we trigger our DBT transformations <em>only</em> after a successful load?</p><p>We don’t poll. We use <strong>another EventArc trigger.</strong></p><p>This second trigger listens for <strong>BigQuery “Job Complete” events</strong>. This is the magic handoff. It triggers a <em>second</em> Cloud Function (post-load-trigger) that inspects the job&#39;s payload.</p><p>This function has two simple paths:</p><ul><li><strong>✅ The Success Path:</strong> If the job payload has no errors, the function calls the Dataform API (which is linked to our GitHub repo) to run the specific transformation models tagged for that table.</li><li><strong>❌ The Failure Path:</strong> If the job failed (schema mismatch, bad rows, etc.), the function logs the <em>entire</em> error payload into a separate “audit” table in BigQuery.</li></ul><p>Everything is stateless, parallel, and driven by events, not schedules.</p><p>A Looker dashboard sits on top of that audit table, giving us a real-time view:</p><ul><li>✅ OK files, the number of lines loaded, …</li><li>❌ Failed files (with the exact BigQuery error message)</li><li>⏳ Pending files (by looking at the Cloud Tasks queue depth)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nrjkFeRN5zhunojQZp18zw.png" /></figure><h3>🧠 4. What Makes It So Effective</h3><ul><li><strong>Zero idle cost:</strong> No data, no spend. Our average 12,600 files/day cost the same as our 50,000 file/day peaks (on a per-file basis).</li><li><strong>Ultra-low cost:</strong> That <strong>$5/day</strong> isn’t for idle VMs. It’s almost entirely for the millions of Cloud Tasks operations and the BigQuery streaming inserts for our audit log. The function invocations and EventArc triggers are pennies.</li><li><strong>Self-healing:</strong> If Dataform is down, the “Job Complete” event will retry. If the file-loader fails, Cloud Tasks retries automatically.</li><li><strong>Scales horizontally:</strong> Every file is an independent event.</li><li><strong>Observability for free:</strong> Cloud Tasks + BigQuery audit logs = a perfect monitoring system with zero effort.</li><li>And the best part:</li></ul><blockquote>“No DAGs were harmed in the making of this platform.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*XcqzjRHtSDe3LSds.gif" /></figure><p>Building this changed how I think about cloud architecture:</p><ul><li><strong>Push logic into the infrastructure</strong>, not the code. Use queues, event-triggers, and managed services as your flow control.</li><li><strong>Don’t build systems that need babysitting.</strong> Let the cloud’s retry mechanisms and logging do the work.</li><li><strong>Serverless &gt; complex orchestrators</strong> for this kind of “move and transform” use case.</li></ul><p>Yes, there’s vendor lock-in. Yes, it’s unconventional. But it’s also beautifully efficient. And that’s a trade-off worth making.</p><h3>🚀 6. Wrap-Up — Building Data Platforms the Cloud-Native Way</h3><p>This architecture proves one thing: You don’t need a massive data team to build a massive data platform. Just lean on the cloud, <em>literally</em>.</p><p>Keep it lean, keep it mean, and let the infrastructure do the heavy lifting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf8409b01a08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How We Designed the Data Infrastructure for One of France’s Largest Sports/Sneaker Retailers]]></title>
            <link>https://medium.com/@aiman.zaki/how-we-designed-the-data-infrastructure-for-one-of-frances-largest-sports-sneaker-retailers-7e416d7fd911?source=rss-b714d8699b06------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e416d7fd911</guid>
            <category><![CDATA[data-ingestion]]></category>
            <category><![CDATA[cloud-architecture]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[dbt]]></category>
            <category><![CDATA[cloud-engineering]]></category>
            <dc:creator><![CDATA[Aiman Zaki]]></dc:creator>
            <pubDate>Mon, 10 Nov 2025 13:53:31 GMT</pubDate>
            <atom:updated>2025-11-10T13:53:31.575Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding the Client’s Problem</h3><p>Our client, one of France’s leading sports and sneaker retailers, faced significant challenges in managing their data. The physical stores and e-commerce platform were isolated data silos that generated vast amounts of information. This varied data landscape led to inefficiencies and limited the ability to create a comprehensive view of the business and customer interactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*y307O4RD3ExcWEyLlJCGOg.png" /><figcaption>Global view of the project with the different sources</figcaption></figure><p>The sales data, spanning multiple systems, included:</p><ul><li><strong>In-store data</strong>: Stored in CEGID Y2, a unified commerce platform.</li><li><strong>Online sales</strong>: Managed in Salesforce Cloud, paired with extensive customer details.</li><li><strong>Product catalog</strong>: Housed in SAP.</li></ul><p>Each data source had a different structure and required extensive normalization and aggregation in <strong>BigQuery</strong>. The customer data platform, Imagino, needed to consolidate all this information into a 360° view of the customer. This complexity posed a major hurdle, particularly when integrating real-time data processing for fast-paced retail operations.</p><h3>Challenges We Faced</h3><ol><li><strong>Diverse Data Structures</strong>: The first significant challenge was the inconsistent format of data across systems. In-store sales were stored in a unique format, while online orders had nested structures that changed dynamically as they progressed through different statuses (e.g., ordered, shipped, returned).</li><li><strong>High Data Volume</strong>: During peak periods, such as sales events, data surged dramatically, with online orders reaching up to 15,000 per hour. This influx risked overwhelming the ingestion pipeline and impacting performance.</li><li><strong>Data Consistency</strong>: Managing updates and ensuring that data was synchronized across systems was complex. For example, returns in-store had to be processed as new transactions to comply with local laws, whereas online order statuses evolved over time.</li><li><strong>Nested JSON Handling</strong>: Existing ingestion frameworks could not handle the deeply nested JSON files produced by various sources, requiring significant customization.</li></ol><h3>Overcoming the Challenges</h3><p><strong>1. Connecting Disparate Data Sources</strong>: Initially, we considered using <strong>Airbyte</strong> or <strong>Fivetran</strong> to connect the systems. However, these options fell short of the flexibility we needed, so we integrated <strong>MuleSoft</strong> as an intermediary. This allowed for more extensive extraction and transformation capabilities, accommodating a wide range of data formats, including complex JSON objects.</p><p><strong>2. Custom Ingestion API Development</strong>: To overcome the limitations in processing nested JSON data, we built a custom route (/file/ingest_json) within our ingestion API:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gintNHxKCBd4V8FQTFNF2g.png" /></figure><ul><li><strong>Recursive Schema Creation</strong>: We developed a function to parse and generate BigQuery schemas dynamically from nested JSON, enabling efficient data loading without manual schema adjustments.</li><li><strong>File Handling at Scale</strong>: During high-traffic periods, thousands of files per minute were uploaded. We utilized <strong>Cloud Tasks</strong> as a buffering mechanism, regulating the flow of files and ensuring smooth ingestion into BigQuery. This prevented data backlogs and kept the process scalable.</li></ul><p><strong>3. Ensuring Data Accuracy and Sync</strong>: Online orders required special handling due to their “living” nature, with status updates affecting order lines over time. Each data change had to trigger a reload that:</p><ul><li>Deleted existing entries for that order in the silver layer.</li><li>Inserted new, updated records to maintain data consistency.</li><li>Implemented incremental loads by comparing timestamps from raw and processed tables, ensuring only new data was processed.</li></ul><p><strong>4. Handling Peak Load Periods</strong>: Peak retail events presented significant challenges, with potential bottlenecks in processing the data influx. To manage this:</p><ul><li><strong>Micro-Batching with Cloud Tasks</strong>: We set up Cloud Tasks to process data in manageable micro-batches, balancing system load by adjusting buffer times dynamically.</li><li><strong>Workflow Orchestration</strong>: Using <strong>Google Cloud Workflows</strong>, we controlled the sequential execution of SQL transformations triggered by ingestion events. This ensured that only one task at a time processed the SQL transformations, allowing for efficient handling of concurrent loads without data conflicts.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q5hWti0SAjPSVDzDU9Buzw.png" /><figcaption>Architecture of the reload events with cloud workflow</figcaption></figure><p><strong>5. Custom Solutions for Transformations</strong>: Our initial templates didn’t support the level of nested JSON processing required. We added new API routes to handle JSON files specifically, refactoring our code to create object-oriented file classes that self-checked against configurations and dynamically generated external tables in BigQuery.</p><h3>Architecture Choices and Design</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ab6inrhH_wKTr8V5Zdo2HQ.png" /></figure><p>Our architecture evolved to include distinct data layers for better organization:</p><ul><li><strong>Bronze Layer</strong>: Raw data ingestion with minimal transformation, preserving the original structure.</li><li><strong>Silver Layer</strong>: Structured data integration with standardized schemas and incremental transformations.</li><li><strong>Gold Layer</strong>: Project-specific, denormalized data optimized for analytics.</li></ul><p>We leveraged <strong>Dataform</strong> for its ability to manage complex dependency trees and execute SQL transformations in the correct order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X_D00KKYtI7mKGTBvifONQ.png" /><figcaption>the entire dependency graph for the sales kpis</figcaption></figure><p>This enabled us to process new product catalogs or customer updates efficiently, ensuring that dependent data (e.g., receipts and orders) were also updated accordingly.</p><p><strong>Workflow Reload Mechanism</strong>: To streamline reloads, we introduced timestamp-based processing. The SQL jobs identified unprocessed data by checking timestamps in raw tables against the last processed data in silver tables:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*sV2YE02prx2rRD8v_1xnGw.png" /></figure><pre>SELECT COALESCE(MAX(creation_datetime), DATETIME(&quot;1900-01-01&quot;))<br>FROM {self()}</pre><p>This strategy eliminated the need for external counters and minimized redundant processing.</p><h3>Conclusion</h3><p>The journey to design this robust data infrastructure was filled with challenges that tested our ingenuity. By leveraging <strong>MuleSoft</strong>, <strong>Google Cloud’s serverless resources</strong>, and custom solutions, we built a system that could withstand the high demands of a fast-paced retail environment. From dynamic JSON processing to managing peak loads, our architecture provided a scalable, efficient, and cohesive data pipeline. This empowered the retailer to achieve real-time insights and drive informed business decisions, enhancing their competitive edge in the market.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e416d7fd911" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>