<?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 Ben Mizrahi on Medium]]></title>
        <description><![CDATA[Stories by Ben Mizrahi on Medium]]></description>
        <link>https://medium.com/@sudo-ben?source=rss-34c3b2df2f3b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zbMtozZi0Wf5T5O0kHflnQ.jpeg</url>
            <title>Stories by Ben Mizrahi on Medium</title>
            <link>https://medium.com/@sudo-ben?source=rss-34c3b2df2f3b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 08:29:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sudo-ben/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[Low-Latency ADK Go 2.0: An In-Memory LLM Engine]]></title>
            <link>https://medium.com/google-cloud/low-latency-adk-go-2-0-an-in-memory-llm-engine-c82b673a248e?source=rss-34c3b2df2f3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c82b673a248e</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[google-adk]]></category>
            <dc:creator><![CDATA[Ben Mizrahi]]></dc:creator>
            <pubDate>Mon, 07 Sep 2026 12:03:44 GMT</pubDate>
            <atom:updated>2026-09-08T15:58:52.317Z</atom:updated>
            <content:encoded><![CDATA[<h4>Embed highly efficient Gemma models directly into your backend systems for lightning-fast, real-time inference.</h4><p>As Generative AI matures, standard architectural patterns are starting to show their cracks. The default approach for most applications today is simple but flawed: your backend makes a REST or gRPC call to a massive, centralized model hosted on a GPU cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KtOIj7SJ9gL956MNvexd4A.jpeg" /></figure><p>But what happens when you are building for strict cloud-native environments where network latency, infrastructure complexity, and data privacy are critical bottlenecks?</p><p>I recently open-sourced <a href="https://github.com/benmizrahi/adk-litert">adk-litert</a>, a low-latency, in-memory LLM engine designed specifically for scalable and real-time inference in Go. By repurposing LiteRT-LM and Google’s highly efficient Gemma models, this project allows you to embed AI directly into your backend systems and <a href="https://github.com/google/adk-go">Google ADK v2</a> agents — achieving lightning-fast speeds with absolutely zero background daemons.</p><p>Here is a look at why this in-process pattern is essential for high-throughput microservices, and how you can apply it to latency-sensitive industries like AdTech and Gaming.</p><h3>The Problem with “Sidecar” AI in Cloud-Native Stacks</h3><p>Most local LLM deployments today rely on separate background processes — tools like Ollama, vLLM, or standalone Python inference servers. While fantastic for prototyping, deploying these in a strict Kubernetes environment introduces significant friction:</p><ol><li><strong>The Network Tax:</strong> Even localhost network calls introduce single-digit millisecond latency. In high-frequency workloads, that overhead is unacceptable.</li><li><strong>Resource Fragmentation:</strong> Managing memory limits and CPU quotas safely between your host application container and a separate inference container is a scheduling nightmare.</li><li><strong>Lifecycle Complexity:</strong> You are forced to manage multi-container pods, handle fragile inter-process communication, and monitor two separate lifecycles for a single microservice.</li></ol><p><a href="https://github.com/benmizrahi/adk-litert">adk-litert</a> eliminates this entirely. Because the inference engine is compiled directly into your Go application, the Gemma model weights are loaded directly into the application’s memory space.</p><p>When your Go code executes a prompt, it’s just a standard function call. No HTTP overhead, no JSON serialization penalties, and no sidecar daemons. Just raw, in-process inference speed.</p><h3>High-Performance Use Cases</h3><p>By eliminating the network hop and leveraging small, open-weights models like Gemma , you unlock AI for scenarios where traditional API-based LLMs are physically too slow or economically unviable.</p><p><strong>1. AdTech: Real-Time Bidding (RTB) &amp; Contextual Matching</strong></p><p>In AdTech, the Real-Time Bidding (RTB) window is notoriously tight. A server must often evaluate a user, analyze page context, and respond to a bid request in under 100 milliseconds. Calling an external OpenAI or Vertex API dynamically is physically impossible within that timeframe.</p><ul><li><strong>The In-Process Solution:</strong> By embedding a quantized Gemma model directly into your Golang bidding microservice using <a href="https://github.com/benmizrahi/adk-litert">adk-litert</a>, you can perform zero-latency contextual analysis, brand-safety checks, or dynamic keyword matching on the fly, entirely within your strict latency budget.</li></ul><p><strong>2. Gaming: Zero-Latency NPC AI</strong></p><p>Modern multiplayer backend servers are heavily Go-based due to its excellent concurrency model. If you want game servers to host intelligent NPCs that react to player behavior in real-time, relying on an external cloud API introduces immersion-breaking lag. Furthermore, per-token API costs scale terribly as concurrent player counts rise.</p><ul><li><strong>The In-Process Solution:</strong> The game server runs the LLM in the exact same process as the game loop. NPCs can generate dialogue, evaluate game states, and make narrative decisions instantaneously without network lag. You get scalable, dynamic game worlds for the fixed cost of your existing compute.</li></ul><p><strong>3. Edge-Native Data Scrubbing</strong></p><p>When processing high volumes of telemetry or log data at the edge, sending that data to a centralized LLM for PII (Personally Identifiable Information) redaction is a massive security risk and bandwidth drain.</p><ul><li><strong>The In-Process Solution:</strong> A Go-based ingest agent running <a href="https://github.com/benmizrahi/adk-litert">adk-litert</a> can intelligently identify and redact sensitive data directly at the edge, before the payload ever travels over the public internet.</li></ul><h3>The Stack: Powering Zero-Latency Inference</h3><p>At its core, this architecture bridges several powerful, highly optimized technologies:</p><ul><li><strong>Go (Golang):</strong> The backbone for high-concurrency, compiled cloud-native services. Go’s lightweight goroutines make it the perfect vehicle for handling thousands of concurrent LLM requests in-memory without the overhead of heavy thread context switching.</li><li><strong>Google ADK v2 (</strong><strong>google.golang.org/adk/v2):</strong> The Agent Development Kit for Go is a code-first toolkit designed for building complex, multi-agent workflows. Unlike Python-heavy agent frameworks, ADK v2 brings native, idiomatic Go performance to agent orchestration. By leveraging ADK v2, developers can build scalable, concurrent agents that seamlessly integrate custom Go functions (tools) natively, making it an ideal pairing for embedded, high-speed execution.</li><li><strong>LiteRT-LM:</strong> While originally famous for running ML models on mobile devices, LiteRT-LM has been repurposed here as an ultra-efficient backend engine. It is specifically optimized for CPU and memory-constrained environments. By bypassing bulky GPU drivers and heavy Python dependencies, LiteRT-LM allows backend servers to execute quantized models directly on the CPU with incredibly low memory footprints and rapid startup times.</li><li><strong>Gemma:</strong> Google’s state-of-the-art open-weights model. It proves that heavily optimized, smaller-parameter models can rival massive cloud APIs when applied to specific, targeted tasks — especially when quantization is utilized.</li></ul><h3>What’s Next: The Full Cycle of Learning</h3><p>Running an in-memory LLM gives you speed, but to truly extract value from 2B or 4B parameter models like Gemma , they need to be highly specialized for your exact domain. An out-of-the-box model doesn’t automatically know how to parse your specific AdTech bid requests or speak like your game’s unique characters.</p><p>In my next article, I’ll be diving into the second half of this architecture: <strong>Fine-Tuning and Continuous Learning.</strong></p><p>I will walk through how to capture the interaction data generated by your Go applications, build an MLOps pipeline to fine-tune your Gemma models, and deploy those updated weights seamlessly back to your embedded <a href="https://github.com/benmizrahi/adk-litert">adk-litert</a> instances—creating a fully automated, full-cycle learning loop.</p><p>Check out the source code and try it yourself: <br><a href="https://github.com/benmizrahi/adk-litert.git">https://github.com/benmizrahi/adk-litert.git</a></p><p><em>If you found this architecture interesting, feel free to star the repo and let me know in the comments how you plan to use in-process LLMs in your own stack!</em></p><blockquote>Disclaimer: This artical and code is provided “as-is” as a demonstration only to illustrate a potential solution. The code does not constitute a Google product or service of any kind, and Google offers no support, warranties, or liability of any kind with its regard. Whoever chooses to use this code accepts all responsibility related to it, including for its implementation, use, and ongoing maintenance. For the avoidance of doubt, this code is not eligible for the Google Open Source Software Vulnerability Rewards Program.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c82b673a248e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/low-latency-adk-go-2-0-an-in-memory-llm-engine-c82b673a248e">Low-Latency ADK Go 2.0: An In-Memory LLM Engine</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a 100% Serverless, Strictly Typed Data Platform on GCP]]></title>
            <link>https://medium.com/google-cloud/100-serverless-strictly-typed-event-driven-data-platform-on-gcp-235ad5a07352?source=rss-34c3b2df2f3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/235ad5a07352</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[data-processing]]></category>
            <dc:creator><![CDATA[Ben Mizrahi]]></dc:creator>
            <pubDate>Wed, 17 Jun 2026 13:05:28 GMT</pubDate>
            <atom:updated>2026-06-18T03:08:58.368Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>If you are building a mobile gaming studio, an ad-tech startup, or any heavily data-driven company, you face a critical bottleneck on day one: <strong>You need to get massive amounts of telemetry from your application into an analytical database fast, reliably, and cheaply.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rWGs-RLajq6ilyAGhV5LYg.png" /></figure><p>Most startups fall into one of two traps:</p><p><strong>Trap 1: The “Wild West” Data Lake.</strong> You dump unstructured JSON payloads directly into storage. It’s fast to build, but within a month, developers change a field name, downstream analytics break, and your data team spends 80% of their time fixing silent corruption.</p><p><strong>Trap 2: The Over-Engineered Behemoth.</strong> You deploy Kafka clusters, Kubernetes nodes, and dedicated stream processors. Suddenly, your infrastructure bill is in the thousands, and you need a dedicated DevOps engineer just to keep the lights on.</p><p>Startups don’t have time for either. What you actually need is an analytics platform that is <strong>strictly typed from the application all the way to the database, infinitely scalable, totally “No-Ops”, and aggressively cost-optimized.</strong></p><p>To solve this, I designed and open-sourced a complete, click-to-deploy, 100% serverless data platform on Google Cloud (GCP). In this article, I’ll break down how it works, the business benefits, and why this architecture is the ultimate cheat code for early to mid-stage startups.</p><p><em>(You can grab the complete Infrastructure-as-Code and start deploying right now from my GitHub repo: </em><a href="https://github.com/benmizrahi/gcp-data-platfrorm/tree/main"><em>benmizrahi/gcp-data-platform</em></a><em>)</em></p><h3>The Solution: A Click-to-Deploy Serverless Architecture</h3><p>The core philosophy of this platform is simple: <strong>Let the cloud provider do the heavy lifting.</strong> By wiring together GCP’s native serverless offerings, we create a pipeline that requires zero provisioning, scales instantly, and enforces data quality at the door.</p><p>Here is the anatomy of the solution:</p><ul><li><strong>Event Ingestion:</strong> Google Cloud Run (Serverless compute)</li><li><strong>The Event Backbone:</strong> Google Cloud Pub/Sub</li><li><strong>Schema Enforcement:</strong> Pub/Sub Native Schema Registry (Protocol Buffers / Apache Avro)</li><li><strong>The Analytical Database:</strong> Google BigQuery</li></ul><h3>1. Strictly Typed: From App to Database</h3><p>The most powerful feature of this platform is <strong>strict typing</strong>. In a data-driven business like ad-tech or gaming, a missing currency field or a malformed timestamp can ruin revenue reports.</p><p>In this architecture, events are defined using <strong>Protobuf</strong>. When your application sends an event, GCP Pub/Sub validates it natively against the schema <em>before</em> accepting it. If the payload is malformed, it is rejected with an error instantly. BigQuery then ingests this validated data perfectly. No broken dashboards, no silent failures, and complete confidence in your data.</p><h3>2. Ready-to-Use &amp; Extensible</h3><p>The entire platform is defined as Infrastructure-as-Code (Terraform). It is a true “click-to-deploy” solution. Furthermore, it relies on a Pub/Sub “fan-out” model. If you want to add a real-time fraud detection service down the line, you don’t touch the existing pipeline. You simply add a new serverless subscription to the existing topic. It is infinitely extensible without touching the core code.</p><h3>Analysis: Why This Wins for Startups</h3><p>Why choose this specific architecture over managed Kafka or traditional ETL tools? Let’s break down the tangible business benefits.</p><h3>Benefit 1: True “No-Ops” and Infinite Scale</h3><p>If your mobile game gets featured on the App Store and traffic spikes from 100 events a minute to 100,000 events a second, this platform won’t break a sweat.</p><ul><li>Cloud Run scales container instances from zero to thousands in milliseconds.</li><li>Pub/Sub handles massive throughput globally without you ever having to think about “partitions” or “brokers.”</li><li>BigQuery allocates query resources dynamically. You don’t need to wake up at 3 AM to scale up a database disk. The infrastructure adapts to your traffic instantly.</li></ul><h3>Benefit 2: Aggressively Cost-Optimized (The Pricing Model)</h3><p>When you are a startup, managing burn rate is everything. Traditional data infrastructure requires paying a baseline cost just to keep servers running, even if nobody is using your app at 4 AM.</p><p>This serverless architecture operates on a <strong>pure pay-for-what-you-use model:</strong></p><ul><li><strong>Compute (Cloud Run):</strong> You pay in increments of 100 milliseconds only when code is actively executing. <em>Scale to zero means $0 cost when idle.</em></li><li><strong>Messaging (Pub/Sub):</strong> You pay per gigabyte of data transmitted. GCP offers a generous free tier every month, meaning early-stage startups might pay pennies.</li><li><strong>Storage/Analytics (BigQuery):</strong> You pay for the data you store and the queries you run.</li></ul><p><strong>The Bottom Line:</strong> If you have zero traffic, your infrastructure bill is effectively $0. If your company goes viral, your costs scale linearly and predictably with your revenue-generating traffic.</p><h3>Benefit 3: Faster Time-to-Market</h3><p>Because this is a click-to-deploy solution, your engineering team isn’t spending weeks debating infrastructure. They deploy the Terraform scripts in minutes, generate their strongly-typed client code, and get back to building the actual product.</p><h3>Conclusion</h3><p>Building a data platform used to be a massive undertaking reserved for companies with dedicated data engineering teams and large budgets. Today, by leveraging serverless architecture and native cloud schema registries, you can achieve enterprise-grade reliability on a startup budget.</p><p>This architecture gives you the holy grail of data engineering: strict typing so your data is always accurate, infinite scale so you never drop an event, and zero-ops so your engineers can focus on product, not pipelines.</p><p>If you want to stop fighting your data infrastructure and start getting insights, check out the complete code and deployment guide here: <br><a href="https://github.com/benmizrahi/gcp-data-platfrorm/tree/main">🔗 <strong>Deploy the Platform on GitHub</strong></a></p><p><em>If this architecture helps your startup scale, feel free to drop a star on the repo or share how you’re using it in the comments!</em></p><p><strong>Happy Hacking :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=235ad5a07352" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/100-serverless-strictly-typed-event-driven-data-platform-on-gcp-235ad5a07352">Building a 100% Serverless, Strictly Typed Data Platform on GCP</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The ADK Guide: Tips, Tricks and Patterns for Production Agents]]></title>
            <link>https://medium.com/google-cloud/the-adk-survival-guide-tips-tricks-and-patterns-for-production-agents-abdc73d99588?source=rss-34c3b2df2f3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/abdc73d99588</guid>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[google-adk]]></category>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Ben Mizrahi]]></dc:creator>
            <pubDate>Mon, 09 Feb 2026 12:07:10 GMT</pubDate>
            <atom:updated>2026-02-16T13:23:52.027Z</atom:updated>
            <content:encoded><![CDATA[<h4>Architecting Resilient and Scalable agents with some battle tested tips &amp; tricks</h4><p>Building an AI agent is easy; building one that survives thousands of turns without hallucinating or hitting rate limits is the real challenge. Using the Google Agent Development Kit (ADK), the key to stability lies in a single architectural pattern: Compiled Context.</p><h3>The Core Philosophy: State != Context</h3><p>To build reliable agents, you must distinguish between your storage and your “thinking” space.</p><ul><li><strong>State (The Database):</strong> Persistent, theoretically infinite storage. It holds everything about the user, session history, and application status.</li><li><strong>Context (The RAM):</strong> The immediate prompt window sent to the LLM. It is expensive, limited, and volatile.</li></ul><blockquote><strong><em>The Golden Rule:</em></strong><em> If you dump your entire State into your Context, your agent in high risk to fail. The goal is to keep the </em><strong><em>State rich</em></strong><em> and the </em><strong><em>Context lean.</em></strong></blockquote><h3>1. Dynamic System Templating</h3><p>Instead of relying on the LLM to “remember” facts from a long chat history, inject critical data directly into the system instructions using ADK templates.</p><p><strong>Why it works:</strong> It ensures the most vital information resides in the “System Prompt,” the area of highest attention for the model.</p><pre># DEFINE THE AGENT<br># Placeholders {user_name} and {user_language} are injected at runtime<br>root_agent = Agent(<br>    name=&quot;root_agent&quot;,<br>    model=&quot;gemini-3-pro-preview&quot;,<br>    instruction=&quot;&quot;&quot;<br>      You are a helpful assistant.<br>      - Current User: {user_name}<br>      - Language: {user_language}<br>      <br>      Always respond in the user&#39;s preferred language.<br>    &quot;&quot;&quot;<br>)<br><br># RUNTIME EXECUTION<br>async def main():<br>    session_service = InMemorySessionService()<br>    session = await session_service.create_session(<br>        user_id=&quot;u123&quot;,<br>        state={&quot;user_language&quot;: &quot;Spanish&quot;, &quot;user_name&quot;: &quot;Maria&quot;}<br>    )<br><br>    runner = Runner(agent=root_agent, session_service=session_service)<br>    # Result: &quot;¡Hola Maria! ¿En qué puedo ayudarte?&quot;</pre><h3>2. Deterministic State Updates via Events</h3><p>One of the powerful features of the ADK is the ability to update the <strong>State</strong> without sending a new chat message. Never “chat” your way into a state change (e.g., “The user is now logged in”). Instead, use the Event system to explicitly modify the session state.</p><p><strong>Why it works:</strong> This creates a deterministic record of truth. If a background process finishes or a user changes a setting in your UI, you push an Event. The next time the LLM runs, it sees the updated values via the system template automatically.</p><pre>............................<br>async def main():<br>    ...........................<br>    # First Run: Uses initial state (English/Google)<br>    events = runner.run_async(<br>        user_id=&quot;user_123&quot;, session_id=&quot;session_456&quot;,<br>        new_message=types.Content(role=&quot;user&quot;, parts=[types.Part(text=&quot;Hello World&quot;)])<br>    )<br>    # Output: &quot;Hello Google!&quot;<br><br>    # --- SIMULATE A SYSTEM EVENT ---<br>    # We update the state delta without the user saying anything<br>    actions_with_update = EventActions(state_delta={<br>         &quot;user_language&quot;: &quot;French&quot;,<br>         &quot;user_name&quot;: &quot;Jean&quot;<br>    })<br>    <br>    system_event = Event(<br>        invocation_id=&quot;inv_login_update&quot;,<br>        author=&quot;system&quot;, <br>        actions=actions_with_update,<br>        timestamp=current_time()<br>    )<br>    await session_service.append_event(session, system_event)<br>    <br>    # Second Run: Agent automatically detects the French/Jean state<br>    response_events = runner.run_async(<br>        user_id=&quot;user_123&quot;, session_id=&quot;session_456&quot;,<br>        new_message=types.Content(role=&quot;user&quot;, parts=[types.Part(text=&quot;Greet me again&quot;)])<br>    )<br>    # Output: &quot;Bonjour Jean !&quot;<br><br>asyncio.run(main())</pre><h3>3. Favor Primitive Parameters for Tools</h3><p>When defining functions (tools) for your agent, strictly avoid passing complex class objects or deeply nested dictionaries- prefer relying on keys and not on entire objects.</p><p><strong>Why it works:</strong> LLMs are probabilistic. They tend to handle primitives more reliably at extracting strings, integers, and booleans. Forcing them to hallucinate a complex UserProfile object structure increases the &quot;cognitive load&quot; and leads to broken tool calls even if you document it well enough.</p><pre># ❌ AVOID: Complex Objects<br>def update_profile_bad(profile: UserProfile):<br>    pass<br><br># ✅ PREFER: Primitives<br>def update_profile_good(user_id: int, tool_context: ToolContext):<br>    &quot;&quot;&quot;<br>    Updates user profile.<br>    Args:<br>        user_id : User&#39;s unique id <br>        tool_context: the adk tool context<br>    &quot;&quot;&quot;<br>    user:UserProfile = tool_context.state[user_id]<br>    .....................<br>    .....user update.....<br>    .....................<br>    return { &quot;status&quot;: &quot;ok&quot; }</pre><h3>4. Context Garbage Collection</h3><p>Long running sessions suffer from “blob accumulation” massive PDF dumps or long logs that drown out the agent’s instructions.</p><p><strong>Why it works:</strong> To prevent the <strong>“Lost in the Middle”</strong> phenomenon, you must actively prune the context. Summarize massive inputs into the State, then replace the raw text in the history with a placeholder.</p><pre>async def prune_context(session_service, session):<br>    history = await session_service.get_history(session)<br>    <br>    for event in history:<br>        # If a message exceeds 1000 characters, truncate it<br>        if event.author == &quot;user&quot; and len(event.content.parts[0].text) &gt; 1000:<br>            # 1. Store insights in State<br>            # 2. Replace bulky text with a placeholder<br>            event.content.parts[0].text = &quot;[Large document summarized in State]&quot;<br>            await session_service.update_event(session, event)</pre><h3>5. Modularize with Agent-as-a-Tool</h3><p>In the ADK, an Agent can be a tool. You can pass a “Specialist” agent to a “Root” agent.</p><p><strong>Why it works:</strong> This ensures <strong>Separation of Concerns</strong>. The “Root” agent handles the flow, while the “Booking Agent” handles the messy API logic. Once the specialist finishes, only its final answer returns to the Root, keeping the Root’s context clean of internal reasoning steps.</p><pre># Specialist handles the complexity<br>booking_agent = Agent(name=&quot;booking_expert&quot;, instruction=&quot;Handle flight APIs...&quot;)<br><br># Root handles the user<br>root_agent = Agent(<br>    name=&quot;concierge&quot;,<br>    tools=[booking_agent], <br>    instruction=&quot;If the user wants a flight, delegate to booking_expert.&quot;<br>)</pre><h3>6. Defensive Tool Design: Standardized Try-Catch</h3><p>When an LLM calls a tool that crashes, the entire agent run often fails or, worse, the model begins to hallucinate a “success” message to cover the error.</p><p><strong>Why it works:</strong> By wrapping your tool logic in a try-catch block and returning a structured JSON response (e.g., a &quot;status&quot; field), you give the LLM a clear signal of what went wrong. This allows the agent to explain the error to the user or attempt a different approach rather than crashing the session.</p><pre># GOOD PRACTICE: Defensive programming in tools<br>def process_payment(amount: float, currency: str):<br>    &quot;&quot;&quot;<br>    Processes a user payment.<br>    Returns a dictionary with status and details.<br>    &quot;&quot;&quot;<br>    try:<br>        # Imagine a real API call here<br>        if amount &lt;= 0:<br>            raise ValueError(&quot;Amount must be greater than zero.&quot;)<br>        <br>        # Logic to call payment gateway...<br>        transaction_id = &quot;TXN_98765&quot;<br>        <br>        return {<br>            &quot;status&quot;: &quot;success&quot;,<br>            &quot;transaction_id&quot;: transaction_id,<br>            &quot;message&quot;: f&quot;Successfully processed {amount} {currency}.&quot;<br>        }<br>    except Exception as e:<br>        # Return the error as data, not as a code-level crash<br>        return {<br>            &quot;status&quot;: &quot;error&quot;,<br>            &quot;error_type&quot;: type(e).__name__,<br>            &quot;message&quot;: str(e)<br>        }<br><br># Register the tool<br>agent = Agent(<br>    name=&quot;billing_agent&quot;,<br>    tools=[process_payment],<br>    instruction=&quot;You process payments. If a tool returns an error status, explain it to the user.&quot;<br>)</pre><h3>Summary: The “Exit 0”</h3><p>Building an agent is easy; maintaining its <strong>Sanity Score</strong> across a thousand-turn session is where the real engineering happens. By treating your context as a <strong>compiled view</strong> rather than a <strong>dump file</strong>, you aren’t just writing code — you’re building a deterministic machine in a probabilistic world.</p><p>Keep your State rich, your Context lean, and your tool calls defensive. Your token budget (and your users) will thank you.</p><p><strong>Happy Hacking.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abdc73d99588" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/the-adk-survival-guide-tips-tricks-and-patterns-for-production-agents-abdc73d99588">The ADK Guide: Tips, Tricks and Patterns for Production Agents</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A S.O.L.I.D AI Architecture]]></title>
            <link>https://medium.com/google-cloud/a-s-o-l-i-d-ai-architecture-f43ce8ef40e4?source=rss-34c3b2df2f3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f43ce8ef40e4</guid>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[google-adk]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Ben Mizrahi]]></dc:creator>
            <pubDate>Mon, 26 Jan 2026 15:13:25 GMT</pubDate>
            <atom:updated>2026-01-28T07:15:10.572Z</atom:updated>
            <content:encoded><![CDATA[<h4>How S.O.L.I.D design patterns apply in the modern AI Context engineering and how to implement them using Google ADK</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zt0cLANJWxjE7_1O2ldYRA.png" /></figure><p>In the early 2000s, Robert C. Martin (“Uncle Bob”) introduced the <strong>S.O.L.I.D.</strong> principles to save us from the “spaghetti code” of monolithic software. Today, as we transition from simple chatbots to complex Agentic systems, we are facing a familiar crisis: <strong>Spaghetti Context.</strong></p><p>We’ve all seen it, the “God Prompt.” A 2,000-line instruction block that tries to teach a model how to be a lawyer, a coder, and a customer service rep all at once. It’s fragile, non-deterministic, and impossible to debug.</p><p>To build production-grade agents with <strong>LLM Models </strong>we must stop “prompting” and start “architecting.”</p><h3>1. Single Responsibility Principle (SRP)</h3><blockquote><em>An agent should have one, and only one, reason to change.</em></blockquote><p>In traditional dev, a class shouldn’t handle both database logging and financial calculations. In Agentic design, a single agent shouldn’t handle both “<strong>User Intent Classification</strong>” and “<strong>Data Processing</strong>.”</p><p><strong>The Agentic Shift:</strong> Break your monolith into specialized agents.</p><ul><li><strong>The Spagetti Way:</strong> A SupportAgent that handles billing, technical troubleshooting, and lead generation.</li><li><strong>The S.O.L.I.D. Way:</strong> A RouterAgent that identifies intent and hands off to a BillingAgent or TechnicalAgent.</li><li><strong>The Results:</strong> A robust system that can handle segmented code updates with out risking the entire system with every new feature request.</li></ul><h3>2. Open/Closed Principle (OCP)</h3><blockquote><em>Agents should be open for extension, but closed for modification.</em></blockquote><p>You shouldn’t have to rewrite your agent’s core identity or system instructions every time you add a new capability or <strong>data source</strong>.</p><ul><li><strong>The Spaghetti Way:</strong> Hardcoding new logic into the “God Prompt” whenever a new API is added (e.g., “If the user asks for weather, use this JSON format…”).</li><li><strong>The S.O.L.I.D. Way:</strong> Using a “Plug-and-Play” tool architecture. The agent’s core reasoning loop remains <strong>closed</strong> to modification, while its capabilities are <strong>open</strong> to extension via new Tool injections.</li><li><strong>The Result:</strong> You can add 10 new tools to your system without changing a single word of your agent’s “personality” or primary reasoning instructions.</li></ul><h3>3. Liskov Substitution Principle (LSP)</h3><blockquote>Models should be replaceable with their “sub-types” without altering the correctness of the system.</blockquote><p>In Agentic design, this is about <strong>Model Interchangeability</strong>. The system logic should not depend on the specific quirks of a versioned LLM.</p><ul><li><strong>The Spaghetti Way:</strong> Writing prompts that only work on one specific model version because they rely on that model’s specific hallucination patterns or output formatting.</li><li><strong>The S.O.L.I.D. Way:</strong> Standardizing the <strong>State Object</strong> and <strong>Tool Schema</strong>. If your architecture is solid, you can swap LLM models seamlessly.</li><li><strong>The Result:</strong> Future-proofing. When a faster model is released, you swap the model in your config and the system will work.</li></ul><h3>4. Interface Segregation Principle (ISP)</h3><blockquote>Many client-specific interfaces are better than one general-purpose interface.</blockquote><p>This is the ultimate cure for <strong>Context Bloat</strong>. An agent should only “see” what it needs for the current task.</p><ul><li><strong>The Spaghetti Way:</strong> Giving one agent a “Swiss Army Knife” of 50 tools, leading to high latency, increased costs, and frequent “Tool Hallucinations.”</li><li><strong>The S.O.L.I.D. Way:</strong> Segregating tools into specific interfaces. A Read-Only agent should not even have the delete_record tool in its context window.</li><li><strong>The Result:</strong> Higher accuracy and lower costs. By providing a cleaner “View” to the model, you reduce the probability of the agent picking the wrong tool for the job.</li></ul><h3>5. Dependency Inversion Principle (DIP)</h3><blockquote><em>Depend upon abstractions, not concretions.</em></blockquote><p>High-level agent logic should not depend on low-level API quirks.</p><ul><li><strong>The Spagetti Way:</strong> Writing an instruction that says “Call the Jira API with the following JSON format…”</li><li><strong>The S.O.L.I.D. Way:</strong> The agent calls a tool named create_ticket(). The agent doesn’t care if that tool hits Jira, Trello, or a text file.</li><li><strong>The Result:</strong> You can change your entire backend infrastructure without ever changing a single word of your agent’s instructions.</li></ul><h3>Practical Example: Google ADK Implementation</h3><p>To see these principles in action, let’s look at a concrete implementation using the <strong>Google Agent Development Kit (ADK)</strong>. In this scenario — extracted from the <a href="https://github.com/benmizrahi/a-s.o.l.i.d-ai-context-example">demonstration repository</a> — we build a support system that abstracts the ticketing backend.</p><p>This approach ensures that the agent remains decoupled from the specific infrastructure (Jira, ServiceNow, or a local database), satisfying both the <strong>Dependency Inversion</strong> and <strong>Open/Closed</strong> principles.</p><h3>The Abstraction Layer</h3><p>By defining a TicketingTool as an implementation of the ADK BaseTool, we create a contract. The agent knows <em>what</em> it can do (create or transition a ticket), but it has no knowledge of <em>how</em> the backend processes that request.</p><pre># 1. Dependency Inversion (DIP) in Action<br># We initialize the tool by injecting the specific service implementation.<br># This allows us to swap a mock service for a production Jira service <br># without touching the Agent&#39;s logic.<br><br>ticketing = TicketingTool(service=InMemoryTicketService()) <br><br># For production (Zero changes required to the Agent below):<br># ticketing = TicketingTool(service=JiraTicketService())<br><br># 2. Interface Segregation (ISP)<br># The SupportAgent is only given access to the ticketing functions.<br># It doesn&#39;t see HR tools, payroll tools, or admin tools.<br><br>root_agent = Agent(<br>    name=&quot;SupportAgent&quot;,    <br>    model=&quot;gemini-2.5-flash&quot;,<br>    static_instruction=&quot;&quot;&quot;<br>        You are a SupportAgent designed to assist users with IT support tasks.<br>        Your primary responsibility is managing the lifecycle of support tickets.<br>        Use the TicketingTool to perform operations as requested by the user.<br>    &quot;&quot;&quot;,<br>    tools=[<br>        FunctionTool(func=ticketing.create_ticket),<br>        FunctionTool(func=ticketing.transition_ticket),<br>    ] <br>)</pre><h3>How this implements S.O.L.I.D.</h3><p>This ADK-based approach transforms the prompt from a “script” into a “component.” Here is how the patterns are satisfied in the code above:</p><ul><li><strong>S (Single Responsibility):</strong> The SupportAgent has one job: ticket orchestration. It doesn&#39;t handle billing, auth, or UI—it only manages the ticket lifecycle.</li><li><strong>O (Open/Closed):</strong> The system is <strong>open</strong> to new ticketing providers by adding a new service class, but <strong>closed</strong> to modification of the Agent’s core instructions.</li><li><strong>L (Liskov Substitution):</strong> We can swap models without changing how the TicketingTool or the orchestration logic functions.</li><li><strong>I (Interface Segregation):</strong> The agent isn’t overwhelmed with a “God Tool” containing 50 methods. We explicitly pass only create_ticket and transition_ticket, keeping the context window clean and focused.</li><li><strong>D (Dependency Inversion):</strong> The Agent doesn&#39;t depend on the “Jira” API. It depends on the TicketingTool abstraction. We &quot;inject&quot; the specific service (In-Memory or Jira) at runtime.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wVbeeL7mI54ug-pqj9ugRA.png" /><figcaption>ADK Web — calling create ticket example</figcaption></figure><h3>Conclusion: The Architect’s Mandate</h3><p>The transition from Monolithic Software to Microservices was driven by a need for reliability at scale. The transition from the “God Prompt” to <strong>S.O.L.I.D. Agents</strong> are driven by that same necessity.</p><p>The transition from Monolithic Software to Microservices was driven by a need for reliability at scale. The transition from the “God Prompt” to <strong>S.O.L.I.D. Agents</strong> are driven by that same necessity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f43ce8ef40e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/a-s-o-l-i-d-ai-architecture-f43ce8ef40e4">A S.O.L.I.D AI Architecture</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hi Gemini, Secure the Room]]></title>
            <link>https://medium.com/google-cloud/hi-gemini-secure-the-room-01903d5541f6?source=rss-34c3b2df2f3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/01903d5541f6</guid>
            <category><![CDATA[gemini-live]]></category>
            <category><![CDATA[live-streaming]]></category>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[video-analysis]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Ben Mizrahi]]></dc:creator>
            <pubDate>Tue, 09 Sep 2025 14:12:00 GMT</pubDate>
            <atom:updated>2025-09-10T07:27:41.288Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hi Gemini, Secure the room …</h3><h4>Building a Real-Time AI-Powered Video Streaming Analysis with Google’s Live Stream API and Gemini Live 2.0</h4><p><em>A deep dive into creating a blazingly fast security monitoring system that turns any camera feed into an intelligent guardian</em></p><h3>The Challenge: Real-Time Intelligence at the Edge</h3><p>Picture this: you need to monitor a space for security threats in real-time. Traditional motion detection systems are plagued with false positives from shadows, pets, or swaying trees. What if instead of relying on simple pixel changes, we could leverage Google’s most advanced multimodal AI to understand what’s actually happening in each frame?</p><p>That’s exactly what I built — a real-time security system that combines <a href="https://cloud.google.com/livestream/docs"><strong>Google Live Stream API</strong></a> for ultra-low-latency video processing with <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/models/gemini/2-0-flash#live-api"><strong>Gemini 2.0 Flash Live Preview</strong></a> for intelligent frame analysis. The result? A system that can detect people, faces, gestures, and even respond to spoken keywords with minimum latency.</p><h3>Architecture Overview: The Data Pipeline</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3TdDMYcypeGYqkNS_thrXw.png" /><figcaption>A GCP Architecture Diagram</figcaption></figure><h3>Architecture Key Components: The GCP Power Trio</h3><p>This system runs on three core Google Cloud services that handle the entire pipeline:</p><ul><li><a href="https://cloud.google.com/livestream/docs"><strong>Google Cloud Live Stream API</strong></a><strong>:</strong> This service does the heavy lifting of video ingestion. We feed it our raw camera feed (like RTSP), and it automatically converts it into a reliable web stream (HLS). This saves us from having to build and manage our own complex media server.</li><li><a href="https://cloud.google.com/vertex-ai"><strong>Gemini Live in Vertex AI</strong></a><strong>:</strong> This is the AI “brain.” It provides a live, streaming connection where we send our video frames along with our instructive text prompts (like “count the people”). It analyzes the video in real-time and sends back the structured JSON answers corresponding with the prompt instruction.</li><li><a href="https://cloud.google.com/run"><strong>Cloud Run</strong></a><strong>:</strong> This is the serverless service that runs our backend Go code. It connects everything: it pulls frames from the Live Stream, sends them to Gemini, gets the AI results, and pushes the data to the web UI via WebSockets. We don’t have to manage any servers, and it scales up or down automatically.</li></ul><p>The stream processing service we developed operates on several key principles:</p><ol><li><strong>Frame Throttling</strong>: Capture at 30fps but analyze at 2–3fps to prevent overwhelming the AI model</li><li><strong>Correlation</strong>: Each frame gets a unique ID that’s tracked through the entire pipeline</li><li><strong>Backfilling</strong>: When AI analysis completes, we apply results to subsequent frames until new analysis arrives</li></ol><h3>The Power of Prompt-Only Detection</h3><p>Traditional security systems are limited to what they were trained to detect. Want to detect “people wearing red shirts”? You need a custom dataset. “Cats on kitchen counters”? Another training cycle. “Smoke or fire in server rooms”? Yet another specialized model.</p><p>With Gemini Live, you simply change the prompt:</p><pre>// Detect people - no training required<br>prompt := &quot;Count people in the frame. Return JSON with people_found (boolean) and count (integer).&quot;</pre><pre>// Detect specific clothing - just change the prompt<br>prompt := &quot;Count people wearing red clothing. Return JSON with red_clothing_found (boolean) and count (integer).&quot;</pre><pre>// Detect pets in specific locations - again, just a prompt change<br>prompt := &quot;Detect cats on kitchen surfaces or counters. Return JSON with cats_on_counter (boolean) and description (string).&quot;</pre><pre>// Detect safety hazards - no specialized training<br>prompt := &quot;Look for smoke, fire, sparks, or other safety hazards. Return JSON with hazard_detected (boolean), type (string), and urgency_level (1-10).&quot;</pre><pre>// Detect suspicious behavior - pure natural language<br>prompt := &quot;Analyze if anyone appears to be acting suspiciously, looking around nervously, or attempting to hide something. Return JSON with suspicious_behavior (boolean) and description (string).&quot;</pre><h3>Real-World Prompt Examples from the System</h3><p>The system comes with a configurable prompt that can be updated in real-time through the web interface:</p><pre>// Default finger counting prompt<br>var taskPrompt = &quot;Detect and count the number of fingers shown by the main hand in the frame. Respond ONLY with a single JSON object containing: frame_id (number), fingers_found (boolean), count (integer).&quot;<br><br>// But you can change it to anything:<br>// &quot;Detect if anyone is using a cell phone or mobile device&quot;<br>// &quot;Count the number of face masks being worn properly&quot; <br>// &quot;Look for unattended bags or packages&quot;<br>// &quot;Detect if anyone appears to be falling or in distress&quot;<br>// &quot;Count vehicles in the parking area&quot;<br>// &quot;Identify if doors or windows are open when they should be closed&quot;</pre><h3>Gemini Live Integration with Frame Correlation</h3><p>The integration with Gemini Live ensures each frame gets analyzed with the current prompt while maintaining perfect correlation:</p><pre>// Send frame with unique ID to model<br>msg := fmt.Sprintf(&quot;frame_id=%d; %s&quot;, it.ID, strings.TrimSpace(task))<br>err := session.SendRealtimeInput(genai.LiveRealtimeInput{<br>    Media: &amp;genai.Blob{<br>        MIMEType: &quot;image/jpeg&quot;, <br>        Data: it.JPEG<br>    }, <br>    Text: msg<br>})<br>// The model responds with structured JSON that always includes the frame_id<br>// No matter what you&#39;re detecting, the response format stays consistent</pre><p>This approach revolutionizes realtime video processing because:</p><ol><li><strong>No Training Required</strong>: Deploy new detection capabilities in seconds</li><li><strong>Unlimited Detection Types</strong>: If you can describe it, Gemini can detect it</li><li><strong>Context-Aware</strong>: The AI understands complex scenarios, not just object classification</li><li><strong>Natural Language</strong>: Security rules written in plain English, not code</li><li><strong>Zero Latency Updates</strong>: Change detection parameters without service interruption</li></ol><h3>Smart Buffering and Backfill Strategy</h3><p>One of the trickiest parts was handling the asynchronous nature of AI responses. Frames arrive every 33ms (30fps), but AI analysis might take 200–500ms. The solution? A sophisticated backfill system:</p><pre>func buildBackfillJSON(frameID uint64) string {<br>    if last := getLastResp(); last != nil {<br>        // Reuse last response schema but update frame_id<br>        last[&quot;frame_id&quot;] = frameID<br>        b, _ := json.MarshalIndent(last, &quot;&quot;, &quot;  &quot;)<br>        return string(b)<br>    }<br>    // Fallback to minimal object<br>    obj := map[string]any{&quot;frame_id&quot;: frameID}<br>    b, _ := json.MarshalIndent(obj, &quot;&quot;, &quot;  &quot;)<br>    return string(b)<br>}</pre><p>When a new AI response arrives, we backfill up to 150 subsequent frames so the UI shows consistent captions even during analysis gaps:</p><pre>const maxBackfill = 150<br>endID := latestID<br>if endID &gt; parsedID+maxBackfill {<br>    endID = parsedID + maxBackfill<br>}<br>for id := parsedID + 1; id &lt;= endID; id++ {<br>    if it2, ok := internal.GetFrameByID(id, &amp;mu, &amp;framesBuf); ok {<br>        desc := buildBackfillJSON(it2.ID)<br>        internal.MemUpdateCaption(it2.ID, desc)<br>    }<br>}</pre><h3>Real-Time WebSocket Streaming with Zero-Copy Performance</h3><p>The web UI receives frames via WebSocket with a carefully optimized protocol that separates binary JPEG data from JSON metadata:</p><pre>func (h *WSHub) broadcastNewFrames(useDisk bool, capturesDir string) {<br>    for client := range h.clients {<br>        go func(c *WSClient) {<br>            // Send binary JPEG immediately<br>            c.conn.SetWriteDeadline(time.Now().Add(5 * time.Second))<br>            if err := c.conn.WriteMessage(websocket.BinaryMessage, jpegData); err != nil {<br>                return<br>            }<br>// Follow with metadata<br>            message := WSMessage{<br>                Type: &quot;frame_meta&quot;,<br>                Data: map[string]interface{}{<br>                    &quot;id&quot;:      frame.ID,<br>                    &quot;time&quot;:    frame.Time,<br>                    &quot;caption&quot;: frame.Caption,<br>                },<br>            }<br>            c.conn.WriteJSON(message)<br>        }(client)<br>    }<br>}</pre><p>The client runs at 60fps (16ms intervals) to minimize display latency, while the broadcast system processes new frames as they arrive.</p><h3>Results Website:</h3><p>The results website provides a modern, real-time dashboard for monitoring live video streams analyzed by Gemini AI. The interface features a sleek, dark-themed design optimized for clarity and usability.</p><p>Key features include:</p><ul><li><strong>Live Video Player:</strong> Displays the current frame from the stream with overlays for camera labels and live status indicators.</li><li><strong>Intelligent Captions:</strong> AI-generated captions summarize detected objects and activities, updating in sync with the video.</li><li><strong>Task Control Panel:</strong> Easily switch between detection presets or define custom tasks for Gemini AI, with instant feedback on new frames.</li><li><strong>Dynamic Prompt:</strong> Ability to change prompts and tasks dynamically in the web UI.</li></ul><p>Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j61AoKjfon5PWtISpkC5Iw.png" /><figcaption>Example prompt that dedicate objects in the video realtime</figcaption></figure><h3>Conclusion: AI-Powered Security is Here</h3><p>This project demonstrates how modern AI APIs can be integrated into real-time systems with careful attention to latency and performance. By combining Google’s Live Stream API with Gemini 2.0, we’ve created a security system that’s not just faster than traditional approaches — it’s fundamentally more intelligent.</p><p>The complete source code is available on GitHub, and the system can be deployed in minutes with just a few environment variables. Whether you’re securing a retail space, monitoring a data center, or just want to know when your cat is on the kitchen counter, this AI-powered approach opens up possibilities that simple motion detection could never achieve.</p><p><em>The future of security isn’t just about detecting movement — it’s about understanding what that movement means.</em></p><p><strong>Tech Stack:</strong> Go, Python, JavaScript, WebSockets, Google Cloud Live Stream API, Gemini 2.0 Flash Live Preview, ffmpeg, HTML5 Canvas/Video APIs</p><p><strong>Repository:</strong> <a href="https://github.com/benmizrahi/genai-live-video-security">Available on GitHub</a> with full deployment instructions</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01903d5541f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/hi-gemini-secure-the-room-01903d5541f6">Hi Gemini, Secure the Room</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building & Debugging GCP Service Extensions using Python]]></title>
            <link>https://medium.com/google-cloud/building-debugging-gcp-service-extensions-using-python-97cf4fa7b3e0?source=rss-34c3b2df2f3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/97cf4fa7b3e0</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[gcp-load-balancer]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[extensions-services]]></category>
            <dc:creator><![CDATA[Ben Mizrahi]]></dc:creator>
            <pubDate>Wed, 20 Nov 2024 01:41:49 GMT</pubDate>
            <atom:updated>2024-11-20T01:41:49.272Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*4qk0nRo0UURtmzwAl7LXhg.png" /><figcaption><em>Application Load Balancer plugins</em></figcaption></figure><p>In the age of cloud-native applications, extending core services like load balancers and CDNs with custom behavior is increasingly valuable. Enter the service-extension-template repository — a solution for implementing Python-based service extensions tailored for Google Cloud Platform (GCP).</p><h3>Overview</h3><p>The service-extension-template is a highly practical starting point for developers aiming to implement and deploy a service extension within a GCP environment. It leverages Python and Docker to provide an accessible, customizable framework. This template is especially beneficial for those needing programmable data paths, as it integrates smoothly with services like GCP’s Load Balancer and Media CDN.</p><p><strong>Docs:</strong></p><p><a href="https://cloud.google.com/service-extensions/docs/overview">Service Extensions overview | Google Cloud</a></p><p><strong>Product SDK:</strong></p><p><a href="https://github.com/GoogleCloudPlatform/service-extensions">GitHub - GoogleCloudPlatform/service-extensions: SDKs and Samples for Google Cloud Service Extensions</a></p><h3>How to Implement Service Extensions with Python: A Guide to the service-extension-template</h3><p>In this article, we’ll explore how to service-extension-template, a handy resource for developers aiming to create service extensions using Python on Google Cloud Platform (GCP). This template is particularly useful for those working with GCP’s Load Balancer or Media CDN services, where programmability and customization can significantly enhance functionality.</p><h4>Why Service Extensions?</h4><p>As organizations rely increasingly on cloud infrastructure, extending core cloud services is often necessary to meet specific business needs. Service extensions allow developers to create custom behaviors — such as dynamic caching, rate limiting, or additional security features — beyond what cloud services natively support. GCP’s Service Extensions enable this by allowing customizations in the data path, making it easier to modify request and response flows without altering underlying applications.</p><p>Here are some common scenarios where service extensions enhance Google Cloud services:</p><ul><li><strong>Dynamic Caching</strong>: Adjust cache duration based on user behavior or specific endpoint usage patterns.</li><li><strong>Rate Limiting</strong>: Add throttling rules based on client IP or geographical location.</li><li><strong>Custom Authentication</strong>: Inject custom security headers or integrate additional authentication mechanisms.</li></ul><h4>Getting Started</h4><blockquote><strong>Clone the Repository</strong>: The first step is to clone the service-extension-template repository, which provides a starting point for creating Python-based service extensions.</blockquote><pre>git clone https://github.com/benmizrahi/service-extension-template.git</pre><blockquote><strong>Review the Dependencies</strong>: This template comes with a requirements.txt file that includes essential Python packages. You’ll need to set up a virtual environment and install dependencies by running:</blockquote><pre>pip install -r requirements.txt</pre><blockquote><strong>Local Development with Docker</strong>: The template is Docker-ready, simplifying local development and testing. The provided Dockerfile ensures a consistent environment and makes deployment to GCP more streamlined.</blockquote><blockquote><strong>Configure and Run the Service</strong>: The service-extension-template includes configurations for debugging and interacting with gRPC endpoints. Running the service locally allows you to thoroughly test custom behaviors before deploying them.</blockquote><pre>docker compose up # ruuning the envoy server with callout config<br><br>python3 -m callout.callout_server # start the callout service </pre><p>Using the repository will allow you to <em>install &amp; debug &amp; test</em> the service extension with full illustration of production environment.</p><h4>Final Thoughts</h4><p>The service-extension-template offers a streamlined way to build, test, and deploy Python-based extensions to enhance the performance and flexibility of GCP services. It’s a great resource for developers looking to customize cloud services efficiently, bringing advanced capabilities to GCP’s already robust infrastructure.</p><p>Explore the repository and get started<a href="https://github.com/benmizrahi/service-extention-template"> here</a>.</p><p><a href="https://github.com/benmizrahi/service-extention-template">https://github.com/benmizrahi/service-extention-template</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97cf4fa7b3e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/building-debugging-gcp-service-extensions-using-python-97cf4fa7b3e0">Building &amp; Debugging GCP Service Extensions using Python</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Paperless: Dataproc Serverless Meets Jupyter]]></title>
            <link>https://sudo-ben.medium.com/paperless-dataproc-serverless-meets-jupyter-3c44c6458789?source=rss-34c3b2df2f3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c44c6458789</guid>
            <category><![CDATA[jupyter-notebook]]></category>
            <category><![CDATA[dataproc]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Ben Mizrahi]]></dc:creator>
            <pubDate>Fri, 02 Feb 2024 19:20:55 GMT</pubDate>
            <atom:updated>2024-02-02T19:20:55.511Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*xE6fgkjd9VpjCLZD.png" /><figcaption>serverless computing</figcaption></figure><p>paperless is a Python package designed to streamline the execution of Jupyter Notebooks with a Spark kernel. Unlike traditional approaches that rely on server-based solutions like Dataproc, paperless allows users to seamlessly run batch Jupyter Notebooks with Spark kernel based on Remote Krenel, it provide more flexible and cost effective solution.</p><p><a href="https://pypi.org/project/paperless/">https://pypi.org/project/paperless/</a></p><p><a href="https://github.com/benmizrahi/paperless">GitHub - benmizrahi/paperless: A papermill implementation to run notebooks inside dataproc serverless</a></p><p><strong>What is </strong><a href="https://github.com/nteract/papermill"><strong>Papemill</strong></a> ? it’s a project that focuses on building tools for working with Jupyter Notebooks programmatically. It provides a set of utilities to execute notebooks, making it an essential component for the remote kernel technique employed by paperless. By leveraging Papemill, paperless enables communication with a Spark kernel running remotely, facilitating the execution of Spark-enabled code directly within the Jupyter environment.</p><p><a href="https://github.com/nteract/papermill">GitHub - nteract/papermill: 📚 Parameterize, execute, and analyze notebooks</a></p><p><strong>What is dataproc serverless — </strong>Dataproc’s serverless solution enables users to submit Spark jobs without maintaining a dedicated Spark cluster. It dynamically allocates resources based on workload requirements, providing an elastic and cost-effective solution for distributed data processing — from google docs:</p><blockquote>Use Dataproc Serverless to run Spark batch workloads without provisioning and managing your own cluster. Specify workload parameters, and then submit the workload to the Dataproc Serverless service. The service will run the workload on a managed compute infrastructure, autoscaling resources as needed. Dataproc Serverless charges apply only to the time when the workload is executing</blockquote><p><a href="https://cloud.google.com/dataproc-serverless/docs">Dataproc Serverless documentation | Dataproc Serverless Documentation | Google Cloud</a></p><pre>pip install paperless</pre><p>Installation and usage described in the project README including setup venv and google cloud preparation.</p><p>Enjoy,</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c44c6458789" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Spreadsheet <> CloudRun Jobs — Trigger & Monitor]]></title>
            <link>https://sudo-ben.medium.com/google-spreadsheet-cloudrun-jobs-trigger-monitor-a942e5b893a5?source=rss-34c3b2df2f3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a942e5b893a5</guid>
            <category><![CDATA[cloud-run-job]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[spreadsheets]]></category>
            <dc:creator><![CDATA[Ben Mizrahi]]></dc:creator>
            <pubDate>Thu, 15 Jun 2023 20:37:56 GMT</pubDate>
            <atom:updated>2023-06-15T20:44:27.569Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google Spreadsheet &lt;&gt; CloudRun Jobs — Trigger &amp; Monitor</h3><p>In this article I’m going to explain how you can trigger &amp; monitor <strong>Google Cloud Run job</strong> directly from<strong> Google Spreadsheet</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X0Z1zFtGFpvlt3aLJQpPbw.png" /><figcaption>Example of UI interface inside spreadsheet that updates every 1 min</figcaption></figure><p><strong>Cloud Run Jobs:<br></strong><a href="https://cloud.google.com/run">https://cloud.google.com/run</a></p><blockquote>Cloud Run jobs are a way to run long-running tasks on Google Cloud Platform. They are stateless, event-driven, and serverless, which means that you don’t need to worry about managing servers or infrastructure.</blockquote><p>Generally, Cloud Run provides a<strong> serverless platform</strong> that gives developers a way to deploy containers without <strong>configuring/tuning</strong> infrastructure (machines, node pools, network etc) — we find it very efficient to deploy <strong>stateless</strong> &amp; <strong>standalone</strong> jobs mostly because it’s simple and cost effective.</p><p><strong>Apps Script<br></strong><a href="https://developers.google.com/apps-script">https://developers.google.com/apps-script</a></p><blockquote>Apps Script is a cloud-based platform that lets you write JavaScript code to automate tasks and extend Google Workspace products. It’s easy to use and doesn’t require any prior programming experience.</blockquote><p>Generally, Apps scripts are the way of adding superpowers to drive products by applying some javascript code.</p><p>On the spreadsheet you want click <strong>Extensions -&gt; Apps Script</strong> it will open an editor and also create new project in Apps Script that will be attached to the spreadsheet. Every function that we will define can be bound to images or events inside the related spreadsheet.</p><p>Next, on the App Scripts page go to Settings page and enable <strong>Show “appsscript.json” manifest file in editor</strong> — this will allow us to define extra scopes needed while the end-user will authenticate with Google.</p><p>Next, go to the editor part and replace the Code.gs file content with the following <a href="https://gist.github.com/benmizrahi/fe0fa5e6bd6199a319b1e3db22993fe9#file-cloudrun_trigger-gs">cloudrun_trigger.gs</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a936f6fc445d30713b196154179404b/href">https://medium.com/media/8a936f6fc445d30713b196154179404b/href</a></iframe><p>Replace the following parameters:</p><pre>const cloudrun_jobs = [&#39;gcp-cloudrun-job-name&#39;] // list of cloud run jobs name<br>const cloudrun_project_id = &quot;gcp-project-number&quot; // project number in GCP<br>const cloudrun_project_name = &quot;gcp-project-name&quot; // project name in GCP<br>const cloudrun_region = &quot;gcp-cloudrun-region&quot; // cloudrun jobs region<br><br>const job_start_row = 2; // the row number to start the status display.<br>const job_link_column = &quot;J&quot; // column that will contain a link to the executed job.<br>const job_status_column = &quot;K&quot; // column that will the status of the J[n] job.<br>const update_timestamp_column = &quot;L&quot; + job_start_row //the column that will contain the last update timestamp</pre><p>Next, go to <strong>appsscript.json </strong>and append all missing tags as describe in <a href="https://gist.github.com/benmizrahi/fe0fa5e6bd6199a319b1e3db22993fe9#file-appsscript-json">appsscript.json </a>— this will import dependencies and add the needed scopes to identify vs Google Cloud Platform.</p><p>After you finish those configuration — you can select <strong>TriggerCloudRun </strong>function in the Apps Script editor section and debug the function to see that the job in Google Cloud Console runs successfully.</p><p>Final thing, to make this solution work each user that you want to give ability to execute and monitor the job — must get <strong>Cloud Run Invoker </strong>role in the relevant Google Cloud project — a simple solution in to create a google group and add the group to Google Cloud IAM with the <strong>Cloud Run Invoker </strong>Role -this way you can control the access from Google Groups and not form GCP IAM.</p><p>In conclusion, this technic can allow you as a developer/product — ability to trigger remote jobs and check there progress directly from <strong>Google Spreadsheet</strong> — even if you&#39;re not going to use it as described in this article — I hope this ability will help you along the way.</p><p>Thanks for reading,</p><blockquote><strong><em>Ben Mizrahi <br></em>Cloud &amp; Data Architect</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a942e5b893a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GKE cluster scale zero — tips]]></title>
            <link>https://medium.com/playamp/gke-cluster-scale-zero-tips-49f1d80bee90?source=rss-34c3b2df2f3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/49f1d80bee90</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[autoscaling]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[infrastructure]]></category>
            <dc:creator><![CDATA[Ben Mizrahi]]></dc:creator>
            <pubDate>Mon, 31 Jan 2022 06:25:57 GMT</pubDate>
            <atom:updated>2023-08-12T13:36:11.441Z</atom:updated>
            <content:encoded><![CDATA[<h3>GKE cluster scale to zero — tips</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*eMQR5EhHMkxXxfFr0p2jgg.jpeg" /></figure><p>Kubernetes it an amazing orchestration system. On Google Cloud Platform you can find it also very cost-effective, because GKE provide the ability to downscale node pools to zero — this way you can reduce cost to minimum.</p><p>The use-case we had for scaling Kubernetes to zero is by running Apache Spark batch jobs - Using the <a href="https://github.com/GoogleCloudPlatform/spark-on-k8s-operator">Spark operator</a> we encourage the scaling ability, resource management and docker containers to have a consistent and reliable Spark jobs.</p><p>To do the job we defined 3 node pools in the cluster:</p><ol><li><strong>Low Resources</strong> (2 cpu 1 gb) (auto scaling off) — this pool holds the Spark operator pods and contains minimal amount of resources.</li><li><strong>High Resources</strong> (8 cpu 64 gb) (auto scaling on 0 – 10) – these pools is for the Spark driver pods. Here we used non Preemptible due to the fact that the only place where application lives on and relies on — is the Spark driver pod. We cannot have a node evicted from the pool here.</li><li><strong>High Preemptible</strong> (16 cpu 128 gb) (auto scaling on 0 — 100) — this pool is of in usage of Spark workers, since Spark is resilient by design - we can safely use temporary nodes to reduce cost.</li></ol><p>Yes, we have also defined more node pools. Each one has its own purpose and job definitions, depending on the application we run and job specification; but for our use with those 3 configurations you can start running your job.</p><p>Sooner or later you will notice multiple issues:</p><ol><li><strong>Auto scaling slows</strong> — 10 min. delay between scaling operations. Well, it’s not so cost-optimized.</li><li><strong>Scale To Zero never happens</strong> — when jobs are done you will notice that not all nodes are evicted from the pools. You will have at least one node still up and running and it will never be evicted — this occurs because of kube-system pods that hold the node alive.</li></ol><p>Here are some tricks that can help you tackle those issues:</p><ol><li><strong>Tuning the autoscaler profile</strong></li></ol><p>The default autoscale profile is balanced. Switching to optimize utilization gives us more aggressive downscaling of node and helps us reduce cost — from google docs:</p><blockquote>optimize-utilization: Prioritize optimizing utilization over keeping spare resources in the cluster. When selected, the cluster autoscaler scales down the cluster more aggressively: it can remove more nodes, and remove nodes faster. This profile has been optimized for use with batch workloads that are not sensitive to start-up latency. We do not currently recommend using this profile with serving workloads.</blockquote><p>This is how to apply that on the cluster:</p><pre><em>gcloud container clusters update &lt;cluster name&gt;  --autoscaling-profile optimize-utilization --project &lt;project name&gt;</em></pre><p>2. <strong>Change Kube-System Pods Configurations</strong></p><p>To tackle the next issue we have to tune the kube-system pods — if you will wait for a while you will discover that the autoscaler produces error logs when trying to downscale the node pools to zero. Here are some logs examples:</p><pre>{<br>  &quot;noDecisionStatus&quot;: {<br>    &quot;measureTime&quot;: &quot;1643186659&quot;,<br>    &quot;noScaleDown&quot;: {<br>          ...<br>          &quot;reason&quot;: {<br>            &quot;parameters&quot;: [<br>              &quot;event-exporter-gke-5479fd58c8-hkzh6&quot;<br>            ],<br>            &quot;messageId&quot;: &quot;no.scale.down.node.pod.has.local.storage&quot;<br>          },<br>          ...<br>      ]<br>    }<br>  }<br>}</pre><pre>{<br>  &quot;noDecisionStatus&quot;: {<br>    &quot;noScaleDown&quot;: {<br>          ...<br>          &quot;reason&quot;: {<br>            &quot;parameters&quot;: [<br>              &quot;metrics-server-v0.4.4-857776bc9c-76kv2&quot;<br>            ],<br>            &quot;messageId&quot;: &quot;no.scale.down.node.pod.has.local.storage&quot;<br>          }<br>          ...<br>}</pre><p>You can read more about these issues in the following information provided by google cloud:</p><p><a href="https://github.com/kubernetes/autoscaler/blob/master/cluster-autoscaler/FAQ.md#i-have-a-couple-of-nodes-with-low-utilization-but-they-are-not-scaled-down-why">autoscaler/FAQ.md at master · kubernetes/autoscaler</a></p><p>And open issue on google cloud GitHub repository:</p><p><a href="https://github.com/GoogleCloudPlatform/k8s-stackdriver/issues/359">event-exporter prevents scaledown by cluster-autoscaler · Issue #359 · GoogleCloudPlatform/k8s-stackdriver</a></p><p>I found this information good but didn’t get a practical example of how to apply this in my own cluster — so here you have the instructions and changes you need to apply to get the desired state of autoscaling to zero:</p><ul><li>On the cluster you want to tune — on the kube-system namespace — open the kube-dns-autoscaler config map and change:</li></ul><pre><em>preventSinglePointFailure -&gt; false</em></pre><ul><li>The next step is to create <strong>poddisruptionbudget</strong> for the glbc selector</li></ul><pre><em>kubectl create poddisruptionbudget l7-default-backend-pdb --namespace=kube-system --selector name=glbc --max-unavailable 1</em></pre><p>I hope this helps anyone,</p><p><strong>Ben Mizrahi</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49f1d80bee90" width="1" height="1" alt=""><hr><p><a href="https://medium.com/playamp/gke-cluster-scale-zero-tips-49f1d80bee90">GKE cluster scale zero — tips</a> was originally published in <a href="https://medium.com/playamp">Playamp-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[@Reactivejs - will you take a ride on the bus?]]></title>
            <link>https://sudo-ben.medium.com/reactivejs-will-you-take-a-ride-on-the-bus-19eebad45422?source=rss-34c3b2df2f3b------2</link>
            <guid isPermaLink="false">https://medium.com/p/19eebad45422</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[eventbus]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Ben Mizrahi]]></dc:creator>
            <pubDate>Thu, 28 Oct 2021 13:38:47 GMT</pubDate>
            <atom:updated>2022-03-22T16:17:14.041Z</atom:updated>
            <content:encoded><![CDATA[<p>What is @<a href="https://github.com/providersjs/reactivejs">reactivejs</a> ? <a href="https://github.com/providersjs/reactivejs">reactivejs</a> provides an event bus implementation for communication between NodeJs micro-services. The implementation contains simple but powerful technique that can allow you to communicate between your services with Kafka based communication layer. Another benefit it allows you as a developer to follow <strong>domain-driven-design</strong> while using <strong>event-driven-architecture</strong> with simple and useful API. If you will follow the pattern it will enable you’r services to grow <strong>horizontally</strong> and improve <strong>performance</strong> and <strong>scalability</strong> of the hole system.</p><p>The three most powerful points that this package useful for:</p><ol><li>React to event/batch of events (batch/streaming).</li><li>Produce async event to between domains.</li><li>Produce a sync (non-blocking) message and wait for response.</li></ol><p>Source code can be found here: <a href="https://github.com/providersjs/reactivejs">https://github.com/providersjs/reactivejs</a><br><em>Dependencies:</em> <strong>KafkaJs, Redis, TypeScript</strong></p><h3>@EventBus — the one that consolidate it all</h3><p>The EventBus instance is the single point of communication between the bus and the client — the bus instance contains serval entries that allows you to communicate between services. The main idea that you have to keep in mind is that every service should have a domain and the service should react to events on the domain and respond with an answer or produce the next event on the chain needed — a full example you can find under the example section in the Github repository</p><h3>@ReactAction —decorator of action definition</h3><p>Beside the event bus instance, the package contains a decorator that allows you <strong>(as a client)</strong> to bind a function to specific events in the domain — the idea is very similar to <strong>Routes</strong> on HTTP packages — you define a “route” and bind it into a function that handles that — the decorator itself will inject the message to your function JSON data provided in the message and other identifiers and methods for your usage (like idempotent protections).</p><h3>Two-way, Async communication</h3><p>Working with event bus and producing messages it’s easy! — but what you will do when you’r code need to get some information from another service before progressing with the operation needed? let’s take a look :</p><pre>class OrderService {<br>    getOrderDetails = async (orderId) =&gt; {<br>        const results = dbConnection.getOrderDetails(orderId);<br>        return results;<br>    }<br>}</pre><pre>class ShippingService {<br>    handleShipment = async (orderId) =&gt; {<br>       const orderDetails = ?<br>       await externalAPI(orderDetails)<br>   }  <br>}</pre><p>In this example we have 2 services (described here as classes) — remember that each service is <strong>isolated and cannot call to each other directly (</strong>so don’t get confused here it’s just an example) — well the next question is how can we get the order details between services ? this is two-way communication ! the method on handleShipment needs to get the results back from the OrderService and then process the shipment — of course we can create a route and call between services via HTTP but we want to have one communication layer — the event bus. So let’s see how we transfer this code to be more reactive and event-driven and get the desired state:</p><pre>class OrderService {</pre><pre>@ActionReact({ action: &#39;get&#39;, domain: &#39;orders&#39; })<br>   getOrderDetails = async (message:IEventBusMessage) =&gt; {<br>      const { orderId } = message.payload<br>      const results = dbConnection.getOrderDetails(id);<br>      return results;<br>   }<br>}</pre><pre>class ShippingService {    <br>    handleShipment = async (orderId) =&gt; {<br>       const orderDetails =  await EventBus.getAsync(&#39;orders&#39;, &#39;get&#39;, { payload: { orderId } })<br>     await externalAPI(orderDetails)<br>   }  <br>}</pre><p>In the example above we made our method <strong>reactable to events</strong> — means that every-time a <strong>get</strong> action will be publish on the <strong>order</strong> domain — <strong>getOrderDetails</strong> method will be execute — the shipment service only have to call the EventBus and wait for the promise to be resolved.</p><p>The implementation under this “magic” is by using Redis PubSub to get results back to the specific service, in the GitHub repo there is a diagram that describes exactly how it happens:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*raHybjbutcpTqd9SW2J60g.png" /></figure><ol><li>The <strong>getAsync</strong> method calling the event-bus with the event need to be triggered and params object.</li><li>The event-bus returns a <strong>promise</strong> and creates a <strong>uuid</strong> for this message.</li><li>The event-bus stores this unique key in redis and listen to events on the keys channel with redis subscribe method.</li><li>The event-bus publish the event to the target domain and action.</li><li>The event-bus on the target domain handles the message and return a value to the event-bus instance (or with an exception that also handled by the package).</li><li>The result then stored on the unique key in Redis.</li><li>The modification of the key triggers the subscriber event.</li><li>The subscriber parse the message results and pass it the the callback function to resolve the promise created at stage 2</li><li>The event-bus deletes the keys and removes the subscription on the channel.</li></ol><p>This technique gives us the ability to responded to callback action on every replica of the service if needed.</p><p>for more examples, Issues, PR’s please go to the Github repository and feel free to contribute:</p><p><a href="https://github.com/providersjs/reactivejs">https://github.com/providersjs/reactivejs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19eebad45422" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>