<?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 Tomasz Wolski on Medium]]></title>
        <description><![CDATA[Stories by Tomasz Wolski on Medium]]></description>
        <link>https://medium.com/@twolski1?source=rss-8e9c57816371------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KCPe8B9Ws5w1xZ7uBT_buQ.png</url>
            <title>Stories by Tomasz Wolski on Medium</title>
            <link>https://medium.com/@twolski1?source=rss-8e9c57816371------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 14:22:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@twolski1/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[CXL persistent memory on QEMU]]></title>
            <link>https://medium.com/@twolski1/cxl-persistent-memory-on-qemu-9dc5f6dcba62?source=rss-8e9c57816371------2</link>
            <guid isPermaLink="false">https://medium.com/p/9dc5f6dcba62</guid>
            <category><![CDATA[cxl]]></category>
            <category><![CDATA[cxl-review]]></category>
            <dc:creator><![CDATA[Tomasz Wolski]]></dc:creator>
            <pubDate>Sat, 13 Dec 2025 22:54:35 GMT</pubDate>
            <atom:updated>2025-12-13T22:55:13.317Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*mTXX-hAzidQp1piL3xzAQw.png" /></figure><p><strong>Introduction<br></strong>Compute Express Link (CXL) is a high-performance interconnect designed to expand system with devices such as GPU, FPGA, NIC or memory expanders. The attachment of specialized hardware delivers substantial performance gain and allow for horizontal scaling of the system.</p><p>With support for memory pooling, tiering, and sharing across devices, CXL reshapes server architectures and allows for more optimized use of the resources.</p><p>CXL is built on top of the PCIe physical layer and introduces three protocols:</p><ul><li><strong>CXL.io</strong>: provides PCIe-like configuration, enumeration, and DMA functionality</li><li><strong>CXL.cache: </strong>allows a device to access the CPU’s memory coherently</li><li><strong>CXL.mem:</strong> allows the host to access device memory coherently and efficiently</li></ul><p>CXL Type-3 devices (also known as <strong>CXL memory expanders</strong>) use <strong>CXL.mem</strong> to expose additional memory capacity to the host.</p><p><strong>Setting Up CXL Type-3 mem device in QEMU</strong></p><p>For experiments, <strong>QEMU</strong> system can be used as it already includes support for virtual <strong>CXL memory devices</strong>. This makes it possible to experiment with CXL memory without needing physical hardware.</p><p>In the following example I will use a configuration with backend file used as CXL pmem device.</p><p>First-off, on host system lets create a 4GB file to be used as a CXL memory and a 2MB file for <em>label storage area</em></p><pre># truncate -s 4G cxl-mem-backend.bin<br># truncate -s 2M cxl-pmem-lsa.bin</pre><p>Now, lets define <strong>QEMU </strong>configuration</p><pre>qemu-system-x86_64 \<br>    -drive file=disk.qcow2,index=0,media=disk,id=hd \<br>    -m 4G,slots=8,maxmem=32G \<br>    -machine type=q35,accel=tcg,cxl=on \<br>    -smp 8 \<br>    -object memory-backend-file,id=cxlmem0,share=on,mem-path=./cxl-mem-backend.bin,size=4G \<br>    -device pxb-cxl,bus=pcie.0,id=cxl.1,bus_nr=12 \<br>    -device cxl-rp,port=0,bus=cxl.1,id=root_port13,chassis=0,slot=2 \<br>    -object memory-backend-file,id=cxllsa0,mem-path=./cxl-pmem-lsa.bin,size=2M \<br>    -device cxl-type3,bus=root_port13,persistent-memdev=cxlmem0,lsa=cxllsa0,id=cxl3 \<br>    -device pcie-root-port,id=rp0,bus=pcie.0 \<br>    -M cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=4G \<br>    -device pcie-root-port,id=pci-root-net,chassis=5,slot=5,bus=pcie.0 \<br>    -device virtio-net-pci,netdev=net0,bus=pci-root-net \<br>    -netdev user,id=net0,hostfwd=tcp::2222-:22</pre><p>Once the system boots, we can inspect available memory devices</p><pre># cxl list -DMu<br>[<br>  {<br>    &quot;memdevs&quot;:[<br>      {<br>        &quot;memdev&quot;:&quot;mem0&quot;,<br>        &quot;pmem_size&quot;:&quot;4.00 GiB (4.29 GB)&quot;,<br>        &quot;serial&quot;:&quot;0&quot;,<br>        &quot;host&quot;:&quot;0000:0d:00.0&quot;,<br>        &quot;firmware_version&quot;:&quot;BWFW VERSION 00&quot;<br>      }<br>    ]<br>  },<br>  {<br>    &quot;root decoders&quot;:[<br>      {<br>        &quot;decoder&quot;:&quot;decoder0.0&quot;,<br>        &quot;size&quot;:&quot;4.00 GiB (4.29 GB)&quot;,<br>        &quot;interleave_ways&quot;:1,<br>        &quot;pmem_capable&quot;:true,<br>        &quot;volatile_capable&quot;:true,<br>        &quot;accelmem_capable&quot;:true,<br>        &quot;qos_class&quot;:0,<br>        &quot;nr_targets&quot;:1<br>      }<br>    ]<br>  }<br>]</pre><p>Creating new region on the memdev:</p><pre># cxl create-region -d decoder0.0 -m mem0 -s 4G region0 -w 1<br>{<br>  &quot;region&quot;:&quot;region0&quot;,<br>  &quot;resource&quot;:&quot;0xa90000000&quot;,<br>  &quot;size&quot;:&quot;4.00 GiB (4.29 GB)&quot;,<br>  &quot;type&quot;:&quot;pmem&quot;,<br>  &quot;interleave_ways&quot;:1,<br>  &quot;interleave_granularity&quot;:256,<br>  &quot;decode_state&quot;:&quot;commit&quot;,<br>  &quot;mappings&quot;:[<br>    {<br>      &quot;position&quot;:0,<br>      &quot;memdev&quot;:&quot;mem0&quot;,<br>      &quot;decoder&quot;:&quot;decoder2.0&quot;<br>    }<br>  ],<br>  &quot;qos_class_mismatch&quot;:true<br>}</pre><p>Next lets provision namespace from region0. Mode <em>fsdax </em>is used so that, <em>ndctl </em>will create a <em>/dev/pmem </em>block device. The device can be further formatted as i.e. ext4.</p><pre># sudo ndctl create-namespace -r region0 -m fsdax<br>{<br>  &quot;dev&quot;:&quot;namespace0.0&quot;,<br>  &quot;mode&quot;:&quot;fsdax&quot;,<br>  &quot;map&quot;:&quot;dev&quot;,<br>  &quot;size&quot;:&quot;3.94 GiB (4.23 GB)&quot;,<br>  &quot;uuid&quot;:&quot;8731d0e9-64bf-4d69-b73d-631343e8c55a&quot;,<br>  &quot;sector_size&quot;:512,<br>  &quot;align&quot;:2097152,<br>  &quot;blockdev&quot;:&quot;pmem0&quot;<br>}</pre><p><strong>Why would one use pmem device</strong></p><p>A <strong>pmem device</strong> is used when one needs <strong>persistent storage that the CPU can access directly with load/store instructions</strong>, rather than going through entire block I/O stack.<br>Compared to traditional block devices, pmem is <strong>byte-addressable, cache-coherent, and can bypass the page cache (DAX)</strong>, giving lower and more predictable latency and enabling in-place data structures instead of block-oriented reads and writes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9dc5f6dcba62" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing Callbacks in Microservice Architecture Using Python — Part 2]]></title>
            <link>https://medium.com/@twolski1/designing-callbacks-in-microservice-architecture-using-python-part-2-eacb2d06599c?source=rss-8e9c57816371------2</link>
            <guid isPermaLink="false">https://medium.com/p/eacb2d06599c</guid>
            <category><![CDATA[celery]]></category>
            <category><![CDATA[message-broker]]></category>
            <category><![CDATA[rabbitmq]]></category>
            <dc:creator><![CDATA[Tomasz Wolski]]></dc:creator>
            <pubDate>Sun, 23 Nov 2025 22:47:46 GMT</pubDate>
            <atom:updated>2025-11-23T22:47:46.261Z</atom:updated>
            <content:encoded><![CDATA[<h3>Designing Callbacks in Microservice Architecture Using Python — Part 2</h3><p>In <strong>Part 1</strong>, I explored how to design callback-style communication between microservices using simple HTTP webhook notifications. While this approach is easy to prototype and common to start with, it becomes increasingly challenging to scale when the system grows, the number of workers increases, or reliability becomes a priority.</p><p>In this article, I’ll redesign the same callback workflow using <strong>RabbitMQ</strong> and <strong>Celery</strong>. This transition is much closer to a production-ready, distributed job execution architecture.</p><p><strong>Why Move Beyond Webhooks</strong></p><p>Webhooks work well in simple 1–to–1 communication and predictable network conditions, but this approach cannot handle well cases when multiple consumers are running in parallel, network becomes unstable or high availability is needed.</p><p>RabbitMQ and Celery addresses most of these challenges <strong>out-of-the-box</strong>, by adding <strong>message persistence</strong>, <strong>reliable queuing</strong>, <strong>distributed processing </strong>or <strong>worker autoscaling</strong>.</p><p><strong>Architecture Overview</strong></p><p>Part 1 architecture:</p><p>Producer → HTTP → Consumer<br>Consumer → HTTP callback → Producer</p><p>Part 2 architecture (message-broker-based)</p><p>Producer → <strong>RabbitMQ task queue</strong> → Workers (Celery)<br>Workers → <strong>Result backend</strong> → Producer</p><p>There are now three logical components:</p><ol><li><strong>Producer service: <br></strong>Sends a job task to RabbitMQ<br>Awaits result asynchronously<br>Correlates jobId → taskId</li><li><strong>Consumer (Celery Workers)<br></strong>Receives jobs to execute<br>Publish results<br>Support retries &amp; fault tolerance</li><li><strong>RabbitMQ + Celery Backend<br></strong>Manages tasks<br>Handles results<br>Provides reliability</li></ol><p><strong>Implementation: Producer (API Service)</strong></p><p>Producer service exposes two API methods, POST/create/joband GET /job/{jobId}. First endpoint is used to create new task and producer generates new job ID, submits work to the Celery and returns immediately job ID to the caller. This call does not block and work is executed asynchronously. Client can further use received job ID and poll the second endpoint for job status or result. Callback endpoint is not needed anymore.</p><pre># producer/app.py<br><br>from fastapi import FastAPI<br>from celery.result import AsyncResult<br>from uuid import uuid4<br>from .tasks import do_work<br><br>app = FastAPI()<br>jobs = {}<br><br>@app.post(&quot;/create/job&quot;)<br>def create_job():<br>    job_id = str(uuid4())<br>    celery_task = do_work.apply_async()<br>    jobs[job_id] = celery_task.id<br>    return {&quot;jobId&quot;: job_id}<br><br>@app.get(&quot;/job/{job_id}&quot;)<br>def get_job(job_id: str):<br>    task_id = jobs.get(job_id)<br>    if not task_id:<br>        return {&quot;status&quot;: &quot;unknown job&quot;}<br><br>    result = AsyncResult(task_id)<br><br>    if result.successful():<br>        return {&quot;status&quot;: &quot;finished&quot;, &quot;result&quot;: result.get()}<br>    elif result.failed():<br>        return {&quot;status&quot;: &quot;failed&quot;}<br>    else:<br>        return {&quot;status&quot;: result.status}</pre><p><strong>Implementation: Celery Worker (Consumer)</strong></p><pre>from celery import Celery<br>import random<br>import asyncio<br><br>app = Celery(<br>    &quot;worker&quot;,<br>    broker=&quot;amqp://guest:guest@localhost:5672/&quot;,<br>    backend=&quot;rpc://&quot;<br>)<br><br>@app.task(bind=True)<br>def do_work(self):<br>    try:<br>        # simulate asynchronous work<br>        result = random.randint(1, 100)<br>        return {&quot;value&quot;: result}<br>    except Exception as exc:<br>        return {&quot;value&quot;: f&quot;error: {exc}&quot;}</pre><p><strong>Why This Scales Better Than Webhooks</strong></p><p>This approach greatly simplifies the service created in Part 1 and introduces a lot more flexibility. Producer logic is simpler and does not need locks and manual synchronization. Also RabbitMQ assures the messages are durable and can automatically retry failed jobs. In conjunction with Celery, the whole architecture can scale and support huge amount of tasks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eacb2d06599c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing callbacks in microservice architecture using Python]]></title>
            <link>https://medium.com/@twolski1/designing-callbacks-in-microservice-architecture-using-python-08e6901c9edb?source=rss-8e9c57816371------2</link>
            <guid isPermaLink="false">https://medium.com/p/08e6901c9edb</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Tomasz Wolski]]></dc:creator>
            <pubDate>Fri, 29 Nov 2024 12:56:13 GMT</pubDate>
            <atom:updated>2024-11-29T12:56:13.649Z</atom:updated>
            <content:encoded><![CDATA[<p>Designing and managing callbacks in a microservice architecture introduces much more challenges compared to monolithic applications. The distributed nature of the system introduces complexities in handling asynchronous communication and ensuring reliable delivery of callback notifications. In the series of articles, I would like to explore most common approaches in designing callbacks in microservice architecture: webhooks vs broker message queues such as RabbitMQ or Kafka.</p><p>In Part 1 below I would like to focus on webhooks and discuss very basic code samples.</p><p><strong>What are webhooks</strong></p><p>Webhook is a resource exposing API via given protocol (i.e. HTTP) and allowing clients to send notifications when specific event occur. In the microservices design, webhooks can be used to provide callback mechanism to task producer when a worker or consumer completes a task.</p><p><strong>Example: webhook callback in producer-consumers pattern</strong></p><p>Following example shows how consumer can notify producer about finished job. This approach runs producer and consumer as separate processes on the same node, but processes could be distributed among different nodes as well.</p><p>Consumer process exposes its REST API and accepts new task via URI:<br> <strong>PUT /create/job/{jobid}</strong></p><p>Producer process exposes REST API webhook, which consumer uses to notify the producer about finished task:<br> <strong>HEAD /notify/job/{jobid}</strong></p><p>In the following example I used <a href="https://connexion.readthedocs.io/en/stable/quickstart.html"><strong>connexion</strong> </a>framework, which allows to firstly design service API specification and then implement handlers. Producer API specification looks as below:</p><pre># api_producer.yaml<br><br>openapi: 3.0.3<br>info:<br>  description: &#39;This is a Producer server instance&#39;<br>  license:<br>    name: Apache 2.0<br>    url: http://www.apache.org/licenses/LICENSE-2.0.html<br>  title: Producer instance<br>  version: 0.1.0<br>paths:<br>  /notify/job/{jobId}:<br>    head:<br>      operationId: notify_job<br>      parameters:<br>        - in: path<br>          name: jobId<br>          schema:<br>            type: string<br>          required: true<br>      responses:<br>        &#39;200&#39;:<br>          description: successful operation<br>      summary: Job notification handler<br>      x-openapi-router-controller: producer</pre><p>Consumer API specification is following:</p><pre># api_consumer.yaml<br><br>openapi: 3.0.3<br>info:<br>  description: &#39;This is a consumer server instance&#39;<br>  license:<br>    name: Apache 2.0<br>    url: http://www.apache.org/licenses/LICENSE-2.0.html<br>  title: Consumer instance<br>  version: 0.1.0<br>paths:<br>  /create/job/{jobId}:<br>    put:<br>      operationId: create_job<br>      parameters:<br>        - in: path<br>          name: jobId<br>          schema:<br>            type: string<br>          required: true<br>      responses:<br>        &#39;200&#39;:<br>          description: successful operation<br>      summary: Job notification handler<br>      x-openapi-router-controller: consumer</pre><p>To synchronize jobs in the producer process I used <a href="https://docs.python.org/3/library/asyncio-sync.html#asyncio.Condition"><strong>Condition</strong></a><strong> </strong>primitive available in Python. When the producer server process starts it creates new task in main() where two new Jobs are initialized and they sent request to workers processes on ports 8091 and 8092 to start remote tasks. Producer code sample is as shown below:</p><pre># producer.py<br><br>import asyncio<br>import connexion<br>import httpx<br><br><br>app = connexion.AsyncApp(__name__)<br>app.add_api(&#39;api_producer.yaml&#39;)<br><br><br>pending_jobs = []<br><br><br>class Job:<br><br>    def __init__(self, jobid):<br>        self.wait_cond = asyncio.Condition()<br>        self.jobid = jobid<br><br>    async def do_remote_work(self, port, timeout):<br>        try:<br>            async with httpx.AsyncClient() as client:<br>                print(f&#39;[{self.jobid}]:requesting consumer at {port} to start the task&#39;)<br>                await client.put(f&#39;http://localhost:{port}/create/job/{self.jobid}&#39;, timeout=timeout)<br>            await self.wait(60)<br><br>        except asyncio.TimeoutError as e:<br>            print(f&#39;Exception: {e}&#39;)<br>        return<br><br>    async def wait(self, timeout):<br>        try:<br>            async with asyncio.timeout(timeout):<br>                async with self.wait_cond:<br>                    print(f&#39;[{self.jobid}]:going to sleep - waiting for notification from consumer..&#39;)<br>                    await self.wait_cond.wait()<br>                    print(f&#39;[{self.jobid}]: ..woken&#39;)<br>        except asyncio.TimeoutError as e:<br>            print(f&#39;Exception: {e}&#39;)<br><br><br>async def notify_job(jobId, *args, **kwargs):<br>    for job in pending_jobs:<br>        if jobId != job.jobid:<br>            continue<br>        async with job.wait_cond:<br>            job.wait_cond.notify()<br>        return &#39;&#39;, 200<br><br>    return &#39;Not Found&#39;, 404<br><br><br>async def main():<br>    worker_addresses = [8091, 8092]<br>    for i, port in enumerate(worker_addresses):<br>        job = Job(f&#39;Job{i}&#39;)<br>        pending_jobs.append(job)<br>        loop.create_task(job.do_remote_work(port=port, timeout=10))<br><br><br>loop = asyncio.get_event_loop()<br>loop.create_task(main())</pre><p>Producer server can be started via uvicorn, for example:</p><pre># uvicorn --host localhost --port 8090 --log-level info  producer:app</pre><p>Consumer code sample looks as follows:</p><pre># consumer.py<br><br>import asyncio<br>import connexion<br>import random<br>import httpx<br><br><br>app = connexion.AsyncApp(__name__)<br>app.add_api(&#39;api_consumer.yaml&#39;)<br><br><br>async def do_work(jobId):<br>    print(f&#39;[consumer][{jobId}]: working...&#39;)<br>    await asyncio.sleep(random.randrange(5))<br>    print(f&#39;[consumer][{jobId}]: ... done. Notifying producer&#39;)<br>    try:<br>        async with httpx.AsyncClient() as client:<br>            await client.head(f&#39;http://localhost:8090/notify/job/{jobId}&#39;)<br>    except Exception as e:<br>        print(f&#39;Exception: {e}&#39;)<br><br><br>async def create_job(jobId, *args, **kwargs):<br>    print(f&#39;[consumer]:Received work request, jobid: {jobId}&#39;)<br><br>    loop = asyncio.get_event_loop()<br>    loop.create_task(do_work(jobId))<br><br>    return &#39;&#39;, 200</pre><p>Consumer server instances on ports 8091 and 8092 are started via <strong>uvicorn</strong>, for example:</p><pre># uvicorn --host localhost --port 8091 --log-level debug consumer:app<br># uvicorn --host localhost --port 8092 --log-level debug consumer:app</pre><p><strong>Putting it all together</strong></p><p>We have spawned three processes: one producer server instance at localhost port 8090 and two consumers at ports 8091 and 8092.<br>Looking at below logs from shell we can see that producer created two Jobs, which then sent tasks to consumer processes. We faked work in the worker processes and each worker slept for random seconds (up to 5).</p><p>Finally, when workers were woken, they notified the producer about finished tasks.</p><p>Producer process server logs:</p><pre># uvicorn --host localhost --port 8090 --log-level info  producer:app<br><br>INFO:     Started server process [24061]<br>INFO:     Waiting for application startup.<br>The swagger_ui directory could not be found.<br>    Please install connexion with extra install: pip install connexion[swagger-ui]<br>    or provide the path to your local installation by passing swagger_path=&lt;your path&gt;<br><br>[Job0]:requesting consumer at 8091 to start the task<br>[Job1]:requesting consumer at 8092 to start the task<br>INFO:     Application startup complete.<br>INFO:     Uvicorn running on http://localhost:8090 (Press CTRL+C to quit)<br>[Job0]:going to sleep - waiting for notification from consumer..<br>[Job1]:going to sleep - waiting for notification from consumer..<br>INFO:     ::1:38508 - &quot;HEAD /notify/job/Job0 HTTP/1.1&quot; 200 OK<br>[Job0]: ..woken<br>INFO:     ::1:38518 - &quot;HEAD /notify/job/Job1 HTTP/1.1&quot; 200 OK<br>[Job1]: ..woken</pre><p>Worker processes logs:</p><pre># uvicorn --host localhost --port 8091 --log-level debug consumer:app<br><br>INFO:     Started server process [23798]<br>INFO:     Waiting for application startup.<br>The swagger_ui directory could not be found.<br>    Please install connexion with extra install: pip install connexion[swagger-ui]<br>    or provide the path to your local installation by passing swagger_path=&lt;your path&gt;<br><br>INFO:     Application startup complete.<br>INFO:     Uvicorn running on http://localhost:8091 (Press CTRL+C to quit)<br>[consumer]:Received work request, jobid: Job0<br>INFO:     ::1:36640 - &quot;PUT /create/job/Job0 HTTP/1.1&quot; 200 OK<br>[consumer][Job0]: working...<br>[consumer][Job0]: ... done. Notifying producer<br><br># uvicorn --host localhost --port 8092 --log-level debug consumer:app<br>INFO:     Started server process [23789]<br>INFO:     Waiting for application startup.<br>The swagger_ui directory could not be found.<br>    Please install connexion with extra install: pip install connexion[swagger-ui]<br>    or provide the path to your local installation by passing swagger_path=&lt;your path&gt;<br><br>INFO:     Application startup complete.<br>INFO:     Uvicorn running on http://localhost:8092 (Press CTRL+C to quit)<br>[consumer]:Received work request, jobid: Job1<br>INFO:     ::1:52422 - &quot;PUT /create/job/Job1 HTTP/1.1&quot; 200 OK<br>[consumer][Job1]: working...<br>[consumer][Job1]: ... done. Notifying producer</pre><p>Implementing callback via webhook is relatively simple, however, it might get really complicated once we think about balancing the work between different workers or high-availability scenarios.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=08e6901c9edb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>