<?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 Lekesh Kumar on Medium]]></title>
        <description><![CDATA[Stories by Lekesh Kumar on Medium]]></description>
        <link>https://medium.com/@lekesh?source=rss-d72623909c00------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Lekesh Kumar on Medium</title>
            <link>https://medium.com/@lekesh?source=rss-d72623909c00------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:30:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lekesh/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[Ingestion of FHIR Data Using Google Cloud Healthcare API]]></title>
            <link>https://blog.searce.com/ingestion-of-fhir-data-using-google-cloud-healthcare-api-10c6a3079d10?source=rss-d72623909c00------2</link>
            <guid isPermaLink="false">https://medium.com/p/10c6a3079d10</guid>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[hl7]]></category>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[fhir]]></category>
            <category><![CDATA[dicom]]></category>
            <dc:creator><![CDATA[Lekesh Kumar]]></dc:creator>
            <pubDate>Thu, 02 Mar 2023 12:31:03 GMT</pubDate>
            <atom:updated>2023-03-03T09:53:19.617Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nZhZpJpXuLejxTBA" /><figcaption><em>“Electronic medical records are, in a lot of ways, the aspect of technology that is going to revolutionise the way we deliver care. Everyone involved in the healthcare enterprise will be able to use information more effectively, not just collect it.”</em></figcaption></figure><p>The aim of this blog is to let users know how we can implement “<strong>Ingestion of FHIR Data Using Google Cloud Healthcare API</strong>”.</p><p>Before we begin, I’d like to provide some context for the problem that the Cloud Healthcare API solves.</p><h3>Overview:</h3><p>This blog shows how to use Cloud Healthcare FHIR APIs to ingest healthcare data in FHIR R4 format (Regular Resources) into BigQuery.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0jRhCFRmKcF-a2aQhw6JpQ.png" /><figcaption>Fig. 1: High-level architecture</figcaption></figure><h3>What is Cloud Healthcare API?</h3><p>Cloud Healthcare API offers a managed solution for storing and accessing healthcare data in Google Cloud, bridging the gap between existing healthcare systems and Google Cloud-hosted applications. Using the API, you can gain access to significant new capabilities for data analysis, machine learning, and application development, which you can then use to create the next generation of healthcare solutions.</p><p>The API consists of three modality-specific interfaces that carry out fundamental business standards for health data:</p><ul><li><strong>FHIR</strong>, a new standard for exchanging health data.</li><li><strong>HL7v2</strong>, the approach to integrating health systems that is most extensively used.</li><li>The predominant standard for radiology and fields connected to imaging is <strong>DICOM</strong>.</li></ul><p><strong>FHIR stores</strong> are being considered in this use-case. FHIR stores contain FHIR resources such as claim resources, patient resources, medication resources, and others.</p><h3>FHIR Versions:</h3><p>FHIR stores in the Cloud Healthcare API support the following versions of the Fast Healthcare Interoperability Resources (FHIR) specification published by Health Level 7 International (HL7).</p><ul><li>DSTU2</li><li>STU3</li><li>R4</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Sp0-AP1-jPqCBoXq" /><figcaption>Fig. 2: FHIR version description</figcaption></figure><p>DSTU2, STU3, and the most recent FHIR® standard update, R4, are all of utmost importance right now. Understanding the three FHIR® versions is crucial, and any service using FHIR® needs to be able to use all three standards.</p><h4>DSTU2</h4><p>Second Draft Standard for Trial Use 2, or DSTU2, was published on October 24, 2015, with numerous revisions from DSTU1, including the inclusion and removal of features, updates to code elements, status, and many more.</p><h4>STU3</h4><p>Release 3 Standard for Trial Use, also known as STU3, was made available on October 24, 2019, and it included more than 2,400 changes.</p><p>It included improvements to the core Clinical, Administrative, and Financial Resources, improvements to the Clinical Decision Support and Clinical Quality Measure</p><p>New tools and a framework were introduced for workflow and task management, along with easier, faster, and more unified creation and publication of FHIR IGs to the web.</p><p>Updates may include technical modifications to RESTful APIs, better resource definitions, version management consolidation, and many other things.</p><h4>R4</h4><p>The October 30, 2019 release of FHIR Version 4 dropped the term Trial Use because it was the first release having normative content. Along with the RESTful API, the XML and JSON formats, nine more Resources, and two essential clinical Resources, Patient and Observation, they were all made normatively available. It contains both normative and STU resources.</p><p>Because some resources in R4 have normative content, they will continue to be adaptable and unchanging as they were in all previous releases. This is huge news since R4 adoption would establish a real standard and represent a significant step towards true interoperability.</p><p>New elements such as age, address, annotation, dosage, money, booleans, and more were added as part of FHIR® R4, further expanding the amount of data you can query.</p><h3>Data Source:</h3><p>Synthetic patient dataset from data hosted within <em>SyntheticMass</em> generated by <a href="https://synthetichealth.github.io/synthea/">SyntheaTM</a>, an open-source patient population simulation made available by <a href="https://health.mitre.org/">The MITRE Corporation</a>.</p><blockquote><strong><em>“</em></strong><em>Jason Walonoski, Mark Kramer, Joseph Nichols, Andre Quina, Chris Moesel, Dylan Hall, Carlton Duffett, Kudakwashe Dube, Thomas Gallagher, Scott McLachlan, Synthea: An approach, method, and software mechanism for generating synthetic patients and the synthetic electronic health care record, Journal of the American Medical Informatics Association, Volume 25, Issue 3, March 2018, Pages 230–238, </em><a href="https://doi.org/10.1093/jamia/ocx079"><em>https://doi.org/10.1093/jamia/ocx079</em></a><strong><em>”</em></strong></blockquote><h3>Technical Implementation:</h3><ol><li>Enable the Cloud Healthcare API in the active project and assign users appropriate IAM roles using the least privilege method. (<a href="https://cloud.google.com/healthcare-api/docs/access-control">refer</a>).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SNZO2wtov3glWt8FgZlIoA.png" /><figcaption><em>Fig. 3: Cloud Healthcare API (APIs &amp; Services)</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1TbXmdi4X3EZXeRJ" /><figcaption><em>Fig. 4: IAM Roles for working with FHIR data (for ref. only)</em></figcaption></figure><p>2. Create a dataset in the Healthcare console</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0QYqYRWYBqekKdlhEmpjgw.png" /><figcaption>Fig. 5: <em>Create a healthcare dataset</em></figcaption></figure><p>3. Create a Data Store inside the dataset:</p><p><em>— Choose appropriate version (</em><a href="https://www.hl7.org/fhir/dstu2/"><em>DSTU2</em></a><em>, </em><a href="https://www.hl7.org/fhir/STU3/"><em>STU3</em></a><em>, </em><a href="https://www.hl7.org/fhir/r4/"><em>R4</em></a><em>)</em></p><p><em>— Check </em><strong><em>Allow update create</em></strong><em> option to allow future creation and updation of data in the same dataset</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P3ZoIsvstHfi6ArcOQm3qw.png" /><figcaption>Fig. 6: <em>Configure the Healthcare Data Store</em></figcaption></figure><p>4. Load the FHIR patient records in a GCS bucket for first time bulk import. To bulk upload data to a GCS bucket, use any of the following methods:</p><p><em>— Using console, upload a folder</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TSBWA1VvMeZzDXv9ZEakAg.png" /><figcaption>Fig. 7: <em>Upload from GCS console</em></figcaption></figure><p><em>— Using gsutil command line tool (recommended)</em></p><pre>gsutil -m cp &quot;/path/to/your/fhir-data/*.json&quot; gs://destination/path/</pre><p>5. Import data from a GCS bucket into the Healthcare Data Store</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3qK9ItGD57h0aoBT1kf8xA.png" /><figcaption>Fig. 8: <em>Importing on console</em></figcaption></figure><p>6. Select the GCS records directory and choose an appropriate FHIR content structure. (<a href="https://cloud.google.com/healthcare-api/docs/reference/rest/v1/projects.locations.datasets.fhirStores/import?_ga=2.205459536.-1356379151.1644997030&amp;_gac=1.226660079.1672914629.CjwKCAiAh9qdBhAOEiwAvxIok9ComnvumY3nLaWKQ-oN68OwZulGsLjw6XwDHo9F_crnuaOVAYoY3BoCwl4QAvD_BwE#contentstructure">refer</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2p3OZxqLCddiydGvzvZCtw.png" /><figcaption>Fig. 9: <em>FHIR import options</em></figcaption></figure><p>7. An <em>ImportResources </em>operation will be initialized and the data will be imported into the Healthcare FHIR Data Store</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qGb0GF8-b4JfTLki" /><figcaption><em>Fig. 10: Bulk import operation on Healthcare console</em></figcaption></figure><p>8. The data can be exported to BigQuery and utilize its capabilities for performing analytics using SQL queries</p><p><em>— Export operation will create one table for each resource type (Patient, Observation, Encounter, etc.) in the target BigQuery dataset. (</em><a href="https://cloud.google.com/healthcare-api/docs/how-tos/fhir-export-bigquery"><em>refer</em></a><em>)</em></p><p><em>— Choose </em><strong><em>Analytics V2</em></strong><em> in Schema type to enable creating repeated data type columns in the resource tables. (</em><a href="https://cloud.google.com/healthcare-api/docs/reference/rest/v1beta1/projects.locations.datasets.fhirStores"><em>refer</em></a><em>)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KDGYbi6Rc0R0IFwY" /><figcaption><em>Fig. 11: Configure an export job to a BigQuery dataset</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JPTdkfU3fkOWfaWo" /><figcaption><em>Fig. 12: BigQuery tables for each resource type</em></figcaption></figure><h3>FHIR Data Analysis Using BigQuery</h3><p><strong>Demonstrate how the data can be denormalized for querying and aggregation:</strong></p><p>— The query below can be used to accomplish this:</p><pre>WITH patient_immunization AS(<br>SELECT P.id AS patientId,<br>  P.name[safe_offset(0)].given AS givenName,<br>  P.name[safe_offset(0)].family AS familyName,<br>  P.birthDate AS birthDate,<br>  I.vaccineCode.text AS vaccine,<br>  DATE(I.occurrence.dateTime) AS vaccinatedDate<br>FROM `demo-data-project.DEMO_UC_9.Patient` P<br>JOIN `demo-data-project.DEMO_UC_9.Immunization` I<br>  ON P.id=I.patient.patientId<br>);<br>SELECT vaccine, count(1) AS vaccineCount<br>FROM patient_immunization<br>GROUP BY vaccine <br>ORDER BY vaccineCount DESC LIMIT 5;</pre><p>Output Preview:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SyjqgbCytN_XXEfe" /><figcaption><em>Fig. 13: Querying data from denormalized table</em></figcaption></figure><p><strong>Demonstrate running SQL queries on the normalized data store:</strong></p><p>As shown in the examples below, you can use SQL queries to extract the fields and values you need from the data.</p><p>Let’s say you want to see all of the values in the field <strong><em>display</em></strong>, which is part of <strong><em>category &gt; coding &gt; display</em></strong>. To do so, you must first unnest <strong><em>category</em></strong> and <strong><em>coding</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AcAO4q9pvSC-08EC" /><figcaption><em>Fig. 14: Nested columns</em></figcaption></figure><p>The query below can be used to accomplish this:</p><pre>SELECT DISTINCT B.display AS Category<br>FROM <br>`demo-data-project.DEMO_UC_9.CarePlan`,<br>   UNNEST(category) AS A,<br>   UNNEST(A.coding) AS B;</pre><p>Output Preview:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3aE8plAFOl_CndF8" /><figcaption><em>Fig. 15: Unnesting data</em></figcaption></figure><h3><strong>Integrate BigQuery with BI tool to display aggregated reports and charts containing FHIR data</strong></h3><p>In Looker Studio, the following three pages have been created to form an intuitive dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fNv_C72a-1g4KAyA" /><figcaption><em>Fig. 16: BI Dashboard — Page 1</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*arbOoTREDvAt-GnG" /><figcaption><em>Fig. 17: BI Dashboard — Page 2</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g1iUPsYpHfeRTKtT" /><figcaption><em>Fig. 18: BI Dashboard — Page 3</em></figcaption></figure><h3>Additional Features from Cloud Healthcare</h3><h4><strong>De-identification / Masking of data:</strong></h4><p>— Cloud Healthcare includes a feature that detects identifiable information, such as protected health information (PHI), and masks, removes, or obscures it from the dataset</p><p>— De-identification can be used for a variety of purposes, including:</p><ul><li><em>Disclosing health information to non-privileged entities</em></li><li><em>Creating and evaluating datasets derived from various sources</em></li><li><em>Data anonymization so that it can be used in machine learning models</em></li></ul><p>— The original dataset, FHIR store, DICOM store, or data are unaffected by de-identification. Depending on how the de-identification is configured, the operation behaves differently:</p><ul><li><em>When data is de-identified at the dataset level, de-identified copies of the original data are written to a new dataset called the destination dataset</em></li><li><em>When data is de-identified at the DICOM or FHIR store level, de-identified copies of the original data are written to an existing dataset’s DICOM or FHIR store</em></li></ul><p>Reference: <a href="https://cloud.google.com/healthcare-api/docs/how-tos/fhir-deidentify">Link</a></p><h4><strong>BigQuery Streaming:</strong></h4><p>— BigQuery Streaming can be used to accomplish the following tasks:</p><ul><li><em>Synchronisation of FHIR Store and BigQuery datasets in near real time</em></li><li><em>Avoid performing a manual bulk export every time new records are added, updated, patched, or deleted from the FHIR Store.</em></li></ul><p>— BigQuery Streaming also adds streaming capabilities to partitioned tables:</p><ul><li><em>Analytics on partitioned tables can improve query performance significantly.</em></li><li><strong><em>Note</em></strong><em>: This function is currently in the Preview stage.</em></li></ul><p>— Analytics V2:</p><ul><li><em>Repeated extension columns are supported, and resources are stored as JSON strings. It is recommended if running complex analytics on the data is needed.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tB0opMUWD3cIHbCTQIZbyw.png" /><figcaption><em>Fig. 19: BigQuery Streaming Configurations</em></figcaption></figure><h3>Conclusion</h3><p>The Cloud Healthcare API provides application access to healthcare data through widely accepted standards-based interfaces such as FHIR, STU3, and DICOM web. These APIs allow data to be ingested into modality-specific stores, which then support data retrieval, updates, searches, and other functions via standard-based interfaces.</p><p>You can then make that data available to applications for analysis, machine learning prediction, and consumer access almost immediately.</p><p>Thank you for reading this blog. Hope it helped you in some way.</p><p>Finally, I would like to thank <a href="https://medium.com/u/c8b818a04e86">Remya Raj</a> and <a href="https://medium.com/u/e59a962731f6">Shreya Goel</a> for their valuable insights and contribution for this blog and special thanks to <a href="https://medium.com/u/be6a394df7fc">Sachdeva Haripriya</a> for creating a wonderful dashboard.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10c6a3079d10" width="1" height="1" alt=""><hr><p><a href="https://blog.searce.com/ingestion-of-fhir-data-using-google-cloud-healthcare-api-10c6a3079d10">Ingestion of FHIR Data Using Google Cloud Healthcare API</a> was originally published in <a href="https://blog.searce.com/">Searce</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cloud Spanner to Pub/Sub | Trigger Downstream Notifications]]></title>
            <link>https://blog.searce.com/cloud-spanner-to-pub-sub-trigger-downstream-notifications-1d698e35f980?source=rss-d72623909c00------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d698e35f980</guid>
            <category><![CDATA[cloud-spanner]]></category>
            <category><![CDATA[pub-sub]]></category>
            <category><![CDATA[notifications]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Lekesh Kumar]]></dc:creator>
            <pubDate>Tue, 18 Oct 2022 09:26:27 GMT</pubDate>
            <atom:updated>2022-10-18T09:26:27.432Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*08COWg3WHpBxr3BS" /><figcaption>Photo by <a href="https://unsplash.com/@epicantus?utm_source=medium&amp;utm_medium=referral">Daria Nepriakhina 🇺🇦</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>In order to help businesses operate in real-time and make smarter business decisions, GCP assists with setting up business infrastructure on the cloud. Real-time marketing, payment processing, fraud detection, game event notification, etc. are a few examples of frequent use cases.</blockquote><h3>Business Case:</h3><p>A Gaming company set-up their infrastructure on GCP to meet high-demand, scalable, and accelerated data insights. To support millions of users, many managed cloud services offered by GCP are used such as: Cloud Spanner for high-performance, global scale database, BigQuery for Data Warehousing and ML Analytics, Cloud Pub/Sub as messaging service.</p><p>The Spanner instance contains several databases and tables that are used to store player achievements and stats, leaderboards, game data, event data, etc. The company wants to notify the players whenever a time-limited and region specific events with exclusive rewards are being added to the game through app notification. The developers want to make sure that the notifications are reached only to a specific group of players that reside in the target location with minimal latency.</p><p>To achieve this, both Spanner’s Change Streams and Pub/Sub’s Filtering technique can be used to watch for data changes from the target table and to filter the insertion or updation of the event data from the target table in real-time.</p><p>The solution &amp; architecture as demonstrated in this article can be applied for this scenario by replacing the Slack endpoint with the hosted game application endpoint.</p><h3>Architecture:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WeZ0bjkdJNzVmCCF" /><figcaption><em>Fig. 1: High-level Architecture Diagram</em></figcaption></figure><h3>Technology Stack:</h3><ul><li><em>Cloud Spanner</em></li><li><em>Compute Engine</em></li><li><em>Cloud Dataflow</em></li><li><em>Cloud Storage</em></li><li><em>Cloud Pub/Sub</em></li><li><em>Slack</em></li></ul><h3>Spanner Change Streams:</h3><p>Google released the Change Streams functionality to track data changes in the Spanner database, such as inserts, updates, and deletions. It offers flexible and scalable methods for streaming data updates to other services. Some use cases include:</p><ul><li>Archival of data changes to Cloud Storage bucket</li><li>Replicate data changes from Spanner tables to Data Warehouses in near-real time, such as BigQuery</li><li>Deploy an application that is triggered by data changes and perform desired operations</li></ul><p>A data change record is written to the internal storage every time Spanner notices a data change in a column being observed by a change streams.</p><p>By default, change streams retains the records for one-day. This can be changed by using DDL and specifying a data-retention period either while creating the change streams, or adjusting it any time in the future.</p><h3>Pub/Sub Filtering Techniques:</h3><p>Cloud Pub/Sub provides a variety of concepts to implement event-driven architecture such as <em>Delivery Guarantees, Order and Duplicates, Filtering and Fanout technique, Unprocessed-message queues, Stream history and replays </em>as mentioned <a href="https://cloud.google.com/solutions/event-driven-architecture-pubsub">here</a>.</p><p>Filtering mechanisms are used by event filters to restrict the events that are sent to subscribers. In this model, every message variation is contained in a single topic and the messaging system’s filtering mechanism assesses each message instead of the subscriber reading each one to see if it applies, keeping it hidden from the other subscribers.</p><p>Only the messages that match the filter are delivered to you when you subscribe to messages. The messages that don’t match the filter are automatically acknowledged by the Pub/Sub service. This mechanism can be helpful when there are multiple event-driven architectures implemented for various purposes.</p><p><em>Note: Messages can be filtered based on their properties but not based on the data they contain</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TjYEOvsRs5SGn-bl" /><figcaption><em>Fig. 2— Pub/Sub models</em></figcaption></figure><p>In this article, Filtering techniques will be implemented to filter each subscription based on the modification types from Spanner tables.</p><h3>Methods to read change streams:</h3><ul><li>Dataflow — using the suggested method for reading change streams, Apache Beam SpannerIO Connector.</li><li>API — using Change Streams Query API. This method allows the flexibility of writing custom code/query that uses Spanner API to read change streams.</li></ul><h3>Pre-requisites:</h3><ol><li>Service account with following permissions/roles:</li></ol><ul><li><em>spanner.databases.select</em></li><li><em>spanner.databases.updateDdl</em></li><li>Storage Admin role</li><li>Dataflow Worker role</li><li><em>pubsub.publisher</em></li><li>Cloud Functions Invoker</li></ul><p>2. An instance created in Cloud Spanner with databases and tables</p><p>3. Change Streams for the target table</p><p>4. Google Cloud Storage Bucket</p><p>5. GCE VM with minimal specifications</p><p>6. A Pub/Sub topic and push subscriptions with a valid endpoint url (Slack app)</p><h3>Technical Steps:</h3><p>The objective of this prototype is to send a notification to an application endpoint whenever a change in the data is detected in Spanner tables.</p><ol><li>Create Change Streams for target table</li></ol><figure><img alt="Spanner Change Stream DDL" src="https://cdn-images-1.medium.com/max/1024/0*Itpv8CCdAYT2MkdV" /><figcaption><em>Fig. 3: Spanner Change Streams DDL</em></figcaption></figure><p>2. Create a VM instance with minimal specifications</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LTJzzDNcZQ7M-aSL" /><figcaption><em>Fig. 4: Virtual Machine configuration</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oBiJD5IyUCcyTnXt" /><figcaption><em>Fig. 5: Attach service account</em></figcaption></figure><blockquote>The code can be cloned from the <a href="https://github.com/thiagotnunes/change-stream-sample">github repo</a>, written using Apache Beam Java SDK and modified as per the requirement.</blockquote><p>For this demonstration, the code has been modified as follows:</p><ul><li>Extract only the relevant information from <em>DataChangeRecord</em> from Spanner Change Streams</li><li>Added attribute to the message data published to Pub/Sub — modType</li><li>Added arguments to provide <em>service account, network and subnetwork</em> in the shell script</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZBTANK8D3Wig2zxC" /><figcaption>Fig 6: Modified code snippet from repo</figcaption></figure><blockquote>The procedures for setting up the environment in a VM instance is provided in the README file <a href="https://github.com/thiagotnunes/change-stream-sample/blob/main/README.md">here</a>. Install JDK and maven with compatible versions as mentioned in the <em>pom.xml</em> file. The code initiates an Apache Beam pipeline using <em>Dataflow runner</em> that reads Spanner Change Streams and publishes the data to a specified Pub/Sub topic.</blockquote><p>3. Create a Cloud Function with HTTP trigger</p><p>Receive the messages from Pub/Sub and send it to the custom Slack application in our workspace.</p><blockquote>Slack custom apps can be created as mentioned <a href="https://api.slack.com/apps">here</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*snvIo_lMcRVvRrRI" /><figcaption><em>Fig. 7: Cloud Function HTTP Trigger</em></figcaption></figure><p>4. Create a Pub/Sub Topic and Subscriptions with Push type with any valid Endpoint URL. In this case, a custom Slack app is used as an endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*_8A02l7qxYXLNsxIxMwdFQ.png" /><figcaption>Fig. 8: Pub/Sub Topic</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5xalGb0soYavp57N" /><figcaption><em>Fig. 9: Push Subscription with Cloud Function endpoint</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aQcCZUfWCD2ogDGW" /><figcaption><em>Fig. 10: Subscription Filter definition</em></figcaption></figure><p>A Pub/Sub push subscription is created with Cloud Function HTTP trigger as the endpoint URL. Similarly, another push subscription is created for <em>UPDATE</em> modification type from spanner table.</p><p>5. DDL or DML on target table for testing</p><p>As the records gets inserted or updated in Spanner table, the Dataflow pipeline picks the data changes from the Spanner Change Streams and publishes to the specified Pub/Sub topic, where the push subscriptions sends the message to the Cloud Function and eventually notifying in the Slack channel using the custom Slack app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q02YhcKGDd8E5Fib" /><figcaption><em>Fig. 11: DDL statement for testing</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*quDuJdHDDpQNX4Nd" /><figcaption><em>Fig. 12: Slack Channel notification</em></figcaption></figure><blockquote>The data received in the Slack channel has been sliced and diced from the data change object according to the need at the code level.</blockquote><h3>Conclusion:</h3><p>This article primarily highlights the streaming capability of Spanner Change Streams to Pub/Sub and also leveraging Pub/Sub’s filtering technique. The main characteristics of this pipeline includes loose coupling and scalability to promote the idea of choreography. This approach is highly resilient as each service work on its own. Hence, downtime of any services does not cause failure across the system. The affected service is easy to identify and can be redeployed at any point of time.</p><p>Hope this blog helps you in some way!</p><p>A very special thanks to <a href="https://medium.com/u/500ffcc0944e">Palak Miharia</a> and <a href="https://medium.com/u/c8b818a04e86">Remya Raj</a> for guiding me and contributing in this blog.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d698e35f980" width="1" height="1" alt=""><hr><p><a href="https://blog.searce.com/cloud-spanner-to-pub-sub-trigger-downstream-notifications-1d698e35f980">Cloud Spanner to Pub/Sub | Trigger Downstream Notifications</a> was originally published in <a href="https://blog.searce.com/">Searce</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>