<?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 Jai Singh on Medium]]></title>
        <description><![CDATA[Stories by Jai Singh on Medium]]></description>
        <link>https://medium.com/@jsl.jaisingh?source=rss-510a7e3982d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ypILbDfC7kFQcTxYFZGrOA.jpeg</url>
            <title>Stories by Jai Singh on Medium</title>
            <link>https://medium.com/@jsl.jaisingh?source=rss-510a7e3982d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:47:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jsl.jaisingh/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[External tables in Databricks on AWS]]></title>
            <link>https://medium.com/@jsl.jaisingh/external-tables-in-databricks-on-aws-b4ae762a181c?source=rss-510a7e3982d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4ae762a181c</guid>
            <category><![CDATA[data-engineer]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Jai Singh]]></dc:creator>
            <pubDate>Sun, 22 Nov 2026 11:09:20 GMT</pubDate>
            <atom:updated>2026-11-22T11:09:20.273Z</atom:updated>
            <content:encoded><![CDATA[<h3>External tables in Databricks on AWS: the complete setup, from S3 bucket to CREATE TABLE</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Nr-mfcPE3t6QHONPnhsrQ.png" /></figure><p><em>Every layer between an S3 bucket and a queryable external table in Unity Catalog, what each one is for, and the errors you will meet if one is missing.</em></p><p>Creating an external table looks like one line of SQL. In practice it sits on top of five other objects, split across two systems: an S3 bucket and an IAM role in AWS, and a storage credential, an external location and a catalog in Databricks. If any one of them is missing or slightly wrong, the error you get rarely names the real cause.</p><p>This article walks through the whole chain in order. Each step shows the console path first, with SQL or the CLI as an alternative, and explains <em>why</em> the step exists, so that when something breaks you know which layer to look at.</p><h3>1. What an external table is, and when to use one</h3><p>In Unity Catalog, every table has metadata (its name, schema, permissions) and data files. The difference between the two table types is <strong>who owns the files</strong>.</p><ul><li>A <strong>managed table</strong> stores its files in a location that Unity Catalog chooses and manages. Dropping the table deletes the data.</li><li>An <strong>external table</strong> stores its files at an S3 path that <strong>you</strong> choose. Dropping the table removes only the metadata. <strong>The files stay where they are.</strong></li></ul><p>Use an external table when:</p><ul><li><strong>Other tools read or write the same files</strong>, for example an AWS service, a Spark job outside Databricks, or a partner’s pipeline.</li><li><strong>The data must outlive the table</strong>, so an accidental DROP TABLE must never delete it.</li><li><strong>The data already exists</strong> in S3, and you want to query it in place without copying it.</li></ul><p>For everything else, managed tables are the simpler default. Databricks optimizes them more aggressively, and you have no paths to manage.</p><h3>2. The chain at a glance</h3><pre>S3 bucket            your data lives here<br>   ^  read / write<br>IAM role             what AWS allows Databricks to do in that bucket<br>   ^  assumed by Databricks&#39; Unity Catalog service<br>Storage credential   Unity Catalog&#39;s record of that IAM role<br>   ^  used by<br>External location    an S3 path + the credential allowed to reach it<br>   ^  CREATE EXTERNAL TABLE / CREATE MANAGED STORAGE<br>Catalog + schema     where the table is registered<br>   ^<br>External table       LOCATION &#39;s3://.../tables/orders&#39;</pre><p>The idea in one sentence: <strong>AWS decides whether Databricks can reach the bucket at all, and Unity Catalog decides which of your users can use that reach.</strong></p><p>That split is why there are so many layers. The IAM role grants broad access to a bucket, but no user ever sees the role. Users get Unity Catalog privileges on the external location and the tables, and Unity Catalog uses the role on their behalf.</p><h3>3. Before you start</h3><p>You need:</p><ul><li><strong>AWS:</strong> permission to create S3 buckets and IAM roles.</li><li><strong>Databricks:</strong> metastore admin, or the CREATE STORAGE CREDENTIAL and CREATE EXTERNAL LOCATION privileges on the metastore. Creating the catalog also needs CREATE CATALOG.</li><li><strong>The same region everywhere.</strong> Put the bucket in the same AWS region as your Unity Catalog metastore. Cross-region access is slower, costs data-transfer charges, can conflict with data residency rules, and (as we will see) can be blocked outright by serverless network policies.</li></ul><p>The examples use these placeholder names. Replace them with your own.</p><pre>Object       Example name<br>S3 bucket    my-uc-bucket<br>IAM role     my-uc-role<br>Storage credential   my_uc_cred<br>External location    my_uc_loc<br>Catalog, schema, table  sales.bronze.orders</pre><h3>4. Step 1: the S3 bucket</h3><p><strong>Console:</strong> S3, then <strong>Create bucket</strong>.</p><p><strong>CLI alternative:</strong></p><pre>aws s3api create-bucket --bucket my-uc-bucket --region &lt;region&gt; \<br>  --create-bucket-configuration LocationConstraint=&lt;region&gt;</pre><pre># confirm the region afterwards<br>aws s3api get-bucket-location --bucket my-uc-bucket</pre><p>Keep a simple layout in mind from the start. Managed data and external tables should live under separate prefixes (more on this in step 9):</p><pre>s3://my-uc-bucket/<br>  managed/sales/        the catalog&#39;s managed location<br>  external/orders/      the external table&#39;s files</pre><h3>5. Step 2: the IAM role, with a placeholder trust policy</h3><p>The IAM role is what Databricks assumes to touch the bucket. Its <strong>trust policy</strong> says who may assume it: Databricks’ Unity Catalog service role, but only when it presents your <strong>external ID</strong>.</p><p>You do not know the external ID yet. Databricks generates it when you create the storage credential in step 4, and step 4 needs the role to exist. So you create the role now with a placeholder, and fix it in step 5.</p><p><strong>Console:</strong> IAM, then <strong>Roles</strong>, then <strong>Create role</strong>, then <strong>Custom trust policy</strong>. Paste:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [{<br>    &quot;Effect&quot;: &quot;Allow&quot;,<br>    &quot;Principal&quot;: { &quot;AWS&quot;: &quot;arn:aws:iam::414351767826:role/unity-catalog-prod-UCMasterRole-14S5ZJVKOTYTL&quot; },<br>    &quot;Action&quot;: &quot;sts:AssumeRole&quot;,<br>    &quot;Condition&quot;: { &quot;StringEquals&quot;: { &quot;sts:ExternalId&quot;: &quot;0000&quot; } }<br>  }]<br>}</pre><p>The principal is Databricks’ Unity Catalog role for AWS commercial regions, as published in the Databricks documentation. When you create the credential, Databricks shows the exact value for your account. Use that value if it differs.</p><p>Skip <strong>Add permissions</strong> for now, name the role my-uc-role, add tags, and create it.</p><h3>6. Step 3: the role’s permissions</h3><p>Next, give the role access to <strong>this bucket only</strong>. Open the role, then <strong>Permissions</strong>, then <strong>Add permissions</strong>, then <strong>Create inline policy</strong>, then <strong>JSON</strong>:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;BucketAccess&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: [<br>        &quot;s3:GetObject&quot;, &quot;s3:PutObject&quot;, &quot;s3:DeleteObject&quot;,<br>        &quot;s3:ListBucket&quot;, &quot;s3:GetBucketLocation&quot;,<br>        &quot;s3:ListBucketMultipartUploads&quot;, &quot;s3:ListMultipartUploadParts&quot;, &quot;s3:AbortMultipartUpload&quot;<br>      ],<br>      &quot;Resource&quot;: [&quot;arn:aws:s3:::my-uc-bucket&quot;, &quot;arn:aws:s3:::my-uc-bucket/*&quot;]<br>    },<br>    {<br>      &quot;Sid&quot;: &quot;SelfAssume&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;sts:AssumeRole&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:iam::&lt;aws-account-id&gt;:role/my-uc-role&quot;<br>    }<br>  ]<br>}</pre><p>The first statement is the least-privilege S3 access: read, write, delete and list in one bucket. The second lets the role assume itself, which Unity Catalog requires (step 5 explains why).</p><p><strong>Optional: file events.</strong> If you will ingest files from this location with Auto Loader or file-arrival triggers, Databricks can subscribe to S3 event notifications instead of repeatedly listing the bucket. That needs extra permissions for bucket notifications, SNS and SQS. Copy the exact policy from the Databricks documentation page on file events rather than writing it by hand. If you only create tables, you do not need it (see step 7).</p><h3>7. Step 4: the storage credential in Databricks</h3><p>A storage credential is Unity Catalog’s record of the IAM role. Creating it is also how you get the external ID.</p><p><strong>Console:</strong> Catalog, then <strong>External data</strong>, then <strong>Credentials</strong>, then <strong>Create credential</strong>:</p><pre>Field               Value<br>Credential type     AWS IAM Role<br>Name                my_uc_cred<br>IAM role            ARN arn:aws:iam::&lt;aws-account-id&gt;:role/my-uc-role</pre><p>After you click <strong>Create</strong>, Databricks shows the <strong>external ID</strong>, usually with a ready-made trust policy. Copy it. In my case, the external ID was my Databricks account ID.</p><p><strong>CLI alternative:</strong></p><pre>databricks storage-credentials create my_uc_cred \<br>  --json &#39;{&quot;aws_iam_role&quot;: {&quot;role_arn&quot;: &quot;arn:aws:iam::&lt;aws-account-id&gt;:role/my-uc-role&quot;}}&#39;</pre><p>The response includes aws_iam_role.external_id and aws_iam_role.unity_catalog_iam_arn.</p><h3>8. Step 5: the final trust policy</h3><p>Back in IAM, open the role, then <strong>Trust relationships</strong>, then <strong>Edit trust policy</strong>, and replace the placeholder:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [{<br>    &quot;Effect&quot;: &quot;Allow&quot;,<br>    &quot;Principal&quot;: { &quot;AWS&quot;: [<br>      &quot;arn:aws:iam::414351767826:role/unity-catalog-prod-UCMasterRole-14S5ZJVKOTYTL&quot;,<br>      &quot;arn:aws:iam::&lt;aws-account-id&gt;:role/my-uc-role&quot;<br>    ]},<br>    &quot;Action&quot;: &quot;sts:AssumeRole&quot;,<br>    &quot;Condition&quot;: { &quot;StringEquals&quot;: { &quot;sts:ExternalId&quot;: &quot;&lt;external-id-from-step-4&gt;&quot; } }<br>  }]<br>}</pre><p>Two things changed, and both matter.</p><p><strong>The external ID is real now.</strong> Databricks’ Unity Catalog role is shared by every Databricks customer. Without a condition, anyone who knew your role’s ARN could register it in <em>their own</em> Databricks account and have Databricks access your bucket for them. This is the classic “confused deputy” problem: a trusted service is tricked into acting for the wrong party. The external ID ties the trust to <em>your</em> account. Databricks only presents your ID when acting for your credential.</p><p><strong>The role trusts itself.</strong> Unity Catalog requires the role to be able to assume itself, which is why it appears as a second principal (and why step 3 allows sts:AssumeRole on its own ARN). You could not add it in step 2, because IAM rejects a trust policy that names a role which does not exist yet.</p><h3>9. Step 6: validate the credential</h3><p>In Databricks, open my_uc_cred and click <strong>Validate configuration</strong>. IAM changes can take a few seconds to apply, so wait briefly first.</p><h3>10. Step 7: the external location</h3><p>An external location connects an S3 path to the credential that may reach it. It is the object users and tables are actually granted against.</p><p><strong>Console:</strong> Catalog, then <strong>External data</strong>, then <strong>External locations</strong>, then <strong>Create external location</strong>, then <strong>Manual</strong>:</p><pre>Field       Value<br>Name        my_uc_loc<br>URL         s3://my-uc-bucket/<br>Storage credential my_uc_cred</pre><p>Click <strong>Create</strong>, then <strong>Test connection</strong>.</p><p><strong>SQL alternative:</strong></p><pre>CREATE EXTERNAL LOCATION my_uc_loc<br>  URL &#39;s3://my-uc-bucket/&#39;<br>  WITH (STORAGE CREDENTIAL my_uc_cred)<br>  COMMENT &#39;Sales data: managed catalog storage and external tables&#39;;</pre><h3>The “File Events Permissions Not Verified” warning</h3><p>You may see this when creating the location:</p><blockquote>Your storage credential can read and write to this location, but file events permissions could not be verified. File events are optional but recommended…</blockquote><p>It appears because the role’s policy does not include the optional file-events permissions from step 3. Read, list, write and delete all passed, so the location works.</p><pre>Choice                          When<br>Force create                    You only create tables, or ingest small amounts. Ingestion falls back to listing files, which is fine at modest scale. Your IAM policy stays minimal.<br>Add the file-events permissions You will run Auto Loader or file-arrival triggers on large or busy prefixes, where listing becomes slow and costly</pre><h3>11. Step 8: privileges on the external location</h3><p>The external location has its own privileges. Grant them to <strong>groups</strong>, not individuals.</p><pre><br>Privilege               Who needs it                               What it allows<br>CREATE EXTERNAL TABLE   Engineers who create external tables       Create tables whose LOCATION is inside this location<br>CREATE MANAGED STORAGE  Admins who create catalogs or schemas      Use a path inside this location as a managed location<br>READ FILES              Engineers who read raw files by path       LIST, read_files(), COPY INTO from a path<br>WRITE FILES             Engineers who write raw files by path      Write directly to paths in the location</pre><pre>GRANT CREATE EXTERNAL TABLE, READ FILES ON EXTERNAL LOCATION my_uc_loc TO `data_engineers`;</pre><p>People who only <strong>query</strong> a table do <strong>not</strong> need any privilege on the external location. Table privileges (step 11) are enough, because Unity Catalog reads the files for them with the credential.</p><h3>12. Step 9: a catalog and schema to hold the table</h3><p>Tables live in a schema, and schemas live in a catalog. On newer metastores there is often no metastore-level root storage, so creating a catalog without a location fails:</p><blockquote>Metastore storage root URL does not exist. … please provide a storage location for the catalog.</blockquote><p>Give the catalog a <strong>managed location</strong> inside your external location. This needs CREATE MANAGED STORAGE on the location.</p><p><strong>Console:</strong> Catalog, then <strong>+</strong>, then <strong>Create a catalog</strong>: name sales, type Standard, storage location my_uc_loc with the sub-path managed/sales.</p><p><strong>SQL alternative:</strong></p><pre>CREATE CATALOG sales MANAGED LOCATION &#39;s3://my-uc-bucket/managed/sales&#39;;<br>CREATE SCHEMA sales.bronze;</pre><p><strong>Keep managed and external paths apart.</strong> Unity Catalog refuses to put an external table inside a managed location. Separate prefixes (managed/ and external/) avoid that collision and make the bucket easy to understand later.</p><h3>13. Step 10: create the external table</h3><p>The LOCATION clause is what makes a table external.</p><pre>CREATE TABLE sales.bronze.orders (<br>  order_id    BIGINT,<br>  customer_id BIGINT,<br>  amount      DECIMAL(10, 2),<br>  order_ts    TIMESTAMP<br>)<br>USING DELTA<br>LOCATION &#39;s3://my-uc-bucket/external/orders&#39;;</pre><pre>INSERT INTO sales.bronze.orders VALUES (1, 101, 25.50, current_timestamp());<br>SELECT * FROM sales.bronze.orders;</pre><p>To create it you need CREATE EXTERNAL TABLE on the external location, plus USE CATALOG, USE SCHEMA and CREATE TABLE on the catalog and schema.</p><p><strong>Over files that already exist.</strong> Point the table at the existing folder and let Databricks read the schema:</p><pre>-- Parquet<br>CREATE TABLE sales.bronze.orders_raw<br>USING PARQUET<br>LOCATION &#39;s3://my-uc-bucket/external/raw/orders/&#39;;</pre><pre>-- CSV with a header row<br>CREATE TABLE sales.bronze.customers_raw<br>USING CSV<br>OPTIONS (header &#39;true&#39;, inferSchema &#39;true&#39;)<br>LOCATION &#39;s3://my-uc-bucket/external/raw/customers/&#39;;</pre><p><strong>Verify the table:</strong></p><pre>DESCRIBE TABLE EXTENDED sales.bronze.orders;</pre><p>Look for Type: EXTERNAL and Location: s3://my-uc-bucket/external/orders.</p><p>For Delta tables, DESCRIBE DETAIL also shows the location, format and file count.</p><h3>14. Step 11: give people access</h3><p>Reading a table takes three privileges, one at each level:</p><pre>GRANT USE CATALOG ON CATALOG sales               TO `analysts`;<br>GRANT USE SCHEMA  ON SCHEMA  sales.bronze        TO `analysts`;<br>GRANT SELECT      ON TABLE   sales.bronze.orders TO `analysts`;</pre><p>USE CATALOG and USE SCHEMA let the group <em>enter</em> the catalog and schema. On their own they show no data. SELECT on the table is the actual read access. Grant SELECT on the schema instead if the group should read every table in it, including future ones.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4ae762a181c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Connect ChatGPT, Claude or Cursor to Enterprise Data Using Databricks Genie One MCP]]></title>
            <link>https://medium.com/@jsl.jaisingh/how-to-connect-chatgpt-claude-or-cursor-to-enterprise-data-using-databricks-genie-one-mcp-55b811aecfcc?source=rss-510a7e3982d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/55b811aecfcc</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[databricks-genie]]></category>
            <dc:creator><![CDATA[Jai Singh]]></dc:creator>
            <pubDate>Tue, 20 Oct 2026 11:20:34 GMT</pubDate>
            <atom:updated>2026-10-20T11:20:34.134Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MYrP5w-_iSWJx06GPI0O-g.png" /><figcaption>Connecting Genie via MCP to Claude, ChatGPT &amp; Cursor</figcaption></figure><p><em>An implementation guide to the endpoint, OAuth setup, client configuration, migration, and governance behind Genie One’s business-aware answers.</em></p><p>To connect ChatGPT, Claude, or Cursor to Databricks Genie One, register the Genie One Model Context Protocol (MCP) server in the client and authenticate using Databricks OAuth with the ai-gateway scope. The server exposes Genie One&#39;s conversational analytics capability, allowing compatible AI clients to ask business questions and receive answers grounded in Genie Ontology, with Unity Catalog permissions enforced on every request.</p><p><strong>Key takeaways</strong></p><ul><li>Genie One MCP is generally available and uses the Unity Gateway endpoint system.ai.genie_one_mcp.</li><li>The previous Beta endpoint, /api/2.0/mcp/genie, is scheduled to sunset on October 31, 2026.</li><li>ChatGPT, Claude, and Cursor use the same Genie One MCP service but have different configuration and OAuth requirements.</li><li>On-behalf-of user authentication is recommended for interactive analytics because it applies the user’s own data permissions.</li></ul><h3>Why connect an AI assistant to Genie One instead of raw tables?</h3><p>Querying data is not the same as understanding what the data means. An assistant asked for net revenue might find gross billing amounts, recognized revenue, and CRM bookings, then select a plausible-looking column that does not match Finance’s definition.</p><p>Genie One MCP gives an external AI assistant access to a business-analysis capability rather than simply exposing a list of tables. Genie One uses <strong>Genie Ontology</strong>, its governed business-context layer, to resolve relevant business terms, metric definitions, relationships, and trusted sources.</p><p>Genie Ontology can combine Unity Catalog semantics defined by teams, such as metric views, domains, and Pages, with context inferred from assets such as dashboards, queries, and Genie Agents. Access to this context is subject to the applicable permissions.</p><p>The architectural distinction matters: an external model writing SQL directly against raw tables must work out much of the business meaning itself. Genie One can instead use the context curated within Databricks before answering the question.</p><h3>How does Genie One MCP work?</h3><p>The Model Context Protocol is an open protocol that lets an AI application discover and invoke tools exposed by a server. In this integration, MCP transports the request; Genie One performs the business-oriented analysis.</p><pre>User asks a business question<br>             |<br>             v<br>   ChatGPT / Claude / Cursor<br>             |<br>             v<br>MCP over HTTP Databricks OAuth<br>             |<br>             v<br>Unity Gateway: system.ai.genie_one_mcp<br>             |<br>             v<br>Genie One + Genie Ontology<br>             |<br>             v<br>SQL execution under the caller&#39;s<br>   Unity Catalog permissions<br>             |<br>             v<br>Answer + Databricks source links</pre><p>The current endpoint is:</p><pre>https://&lt;workspace-hostname&gt;/ai-gateway/mcp-services/system.ai.genie_one_mcp</pre><p>Replace &lt;workspace-hostname&gt; with your Databricks workspace hostname. You can find the available server and its URL under <strong>Unity Gateway → MCPs</strong>.</p><p>The server exposes tools including genie_ask, genie_poll_response, genie_get_query_result, and genie_cancel_response. Clients supporting MCP Apps can use view_ask to display an interactive view.</p><p>A typical request begins with genie_ask, which returns a conversation ID and response ID. The client then checks progress using genie_poll_response. Subsequent questions can reuse the conversation ID, while genie_get_query_result retrieves the full available query result when needed.</p><p>The responses may be truncated to protect the model’s context window. Very large results remain subject to size limits.</p><p>See the <a href="https://docs.databricks.com/aws/en/agents/mcp-tools/genie-mcp">official Genie One MCP documentation</a>.</p><h3>What do you need before connecting?</h3><p>Prepare the following:</p><ul><li>A Databricks workspace with Genie One and Unity Gateway access.</li><li>Permission to execute the MCP and use its parent catalog and schema.</li><li>Access to the underlying data required by your questions.</li><li>A Databricks OAuth app configured for the ai-gateway scope and the exact redirect URL required by your client.</li><li>Network access between the client and the Databricks workspace.</li></ul><p>Databricks-provided MCPs can inherit default EXECUTE grants on system.ai. Administrators should review these grants and restrict access to the appropriate users and groups.</p><h3>How do you migrate from the Genie One MCP Beta endpoint?</h3><p><strong>Update the URL and OAuth scope, then authenticate again.</strong> The older endpoint, https://&lt;workspace-hostname&gt;/api/2.0/mcp/genie, is deprecated and scheduled to sunset on October 31, 2026.</p><p>Current endpointPath : /api/2.0/mcp/genie/ai-gateway/mcp-services/system.ai.genie_one_mcp</p><p>Auth scope : genieai-gateway</p><p>Use this migration checklist:</p><ol><li>Ask an account administrator to configure an OAuth app with the ai-gateway scope and the required client redirect URLs.</li><li>Replace the old endpoint in each ChatGPT, Claude, Cursor, or custom-agent connection.</li><li>Remove and recreate connections where necessary, and sign in again to obtain a token for the new scope.</li><li>Grant the appropriate EXECUTE, USE CATALOG, and USE SCHEMA permissions.</li><li>Verify successful calls and monitor traffic through system.ai_gateway.usage.</li></ol><p>Do not assume that changing the URL alone is sufficient; authentication, permissions, and network access must also work.</p><h3>How do you connect ChatGPT to Genie One MCP?</h3><p>Custom MCP apps in ChatGPT require Developer Mode and an eligible Business, Enterprise, or Edu workspace, with availability controlled by the account and workspace policy.</p><ol><li>In ChatGPT, open <strong>Settings → Apps → Create App</strong> or the corresponding Developer Mode interface available to your workspace.</li><li>Enter the Genie One MCP URL and select OAuth authentication.</li><li>Copy ChatGPT’s exact redirect URL. Databricks documentation specifies https://chatgpt.com/connector_platform_oauth_redirect for this integration.</li><li>Ask an account administrator to register the redirect URL and ai-gateway scope in a Databricks OAuth app.</li><li>Enter the client ID and secret, if applicable, complete sign-in, and enable the connection in a conversation.</li></ol><p>ChatGPT makes server calls from OpenAI’s infrastructure. If workspace IP access lists are enabled, the relevant ChatGPT outbound IP addresses must be permitted.</p><h3>How do you connect Claude to Genie One MCP?</h3><h3>Claude on the web or through custom connectors</h3><ol><li>Register a Databricks OAuth app with the ai-gateway scope and these redirect URLs:</li></ol><ul><li><a href="https://claude.ai/api/mcp/auth_callback">https://claude.ai/api/mcp/auth_callback</a></li><li><a href="https://claude.com/api/mcp/auth_callback">https://claude.com/api/mcp/auth_callback</a></li></ul><p>2. In Claude, open <strong>Settings → Connectors → Add custom connector</strong>.</p><p>3. Enter the Genie One MCP URL and OAuth client details.</p><p>4. Complete sign-in, enable the connector in a conversation, and ask a business question.</p><p>5. Claude connector calls originate from the provider’s infrastructure, so workspace IP restrictions must allow the relevant outbound addresses.</p><h3>Claude Code</h3><p>With the Unity Gateway CLI installed, the recommended setup for coding-agent access is to configure the environment using the documented ug workflow, then add Genie One MCP:</p><pre>ug mcp add --agents claude --names system.ai.genie_one_mcp</pre><p>Follow the sign-in prompts, restart the agent if required, and test the tool. The CLI-based workflow differs from manually registering a custom OAuth app; follow the current <a href="https://docs.databricks.com/aws/en/generative-ai/mcp/connect-clients">Databricks client setup guide</a> for your specific Claude interface.</p><h3>How do you configure Cursor for Genie One MCP?</h3><p>The simplest method is the Unity Gateway CLI. With Cursor Agent installed, run:</p><pre>ug mcp add --agents cursor</pre><p>Choose system.ai.genie_one_mcp from the MCP picker. The CLI registers the connection in ~/.cursor/mcp.json. Restart Cursor or the agent session and ask it to invoke Genie One.</p><p>For manual configuration with OAuth, first have an account administrator create a public OAuth client using the redirect URL http://localhost:3334/oauth/callback and the ai-gateway scope.</p><p>Merge this entry into ~/.cursor/mcp.json, preserving existing servers:</p><pre>{<br>  &quot;mcpServers&quot;: {<br>    &quot;genie-one&quot;: {<br>      &quot;command&quot;: &quot;npx&quot;,<br>      &quot;args&quot;: [<br>        &quot;-y&quot;,<br>        &quot;mcp-remote&quot;,<br>        &quot;https://&lt;workspace-hostname&gt;/ai-gateway/mcp-services/system.ai.genie_one_mcp&quot;,<br>        &quot;3334&quot;,<br>        &quot;--static-oauth-client-info&quot;,<br>        &quot;{\&quot;client_id\&quot;:\&quot;&lt;oauth-client-id&gt;\&quot;}&quot;,<br>        &quot;--static-oauth-client-metadata&quot;,<br>        &quot;{\&quot;scope\&quot;:\&quot;ai-gateway offline_access\&quot;}&quot;<br>      ]<br>    }<br>  }<br>}</pre><p>Replace the workspace hostname and OAuth client ID with the real values. This manual setup requires Node.js and npx. Restart Cursor, complete browser sign-in, and confirm that the agent actually invokes Genie One MCP.</p><h3>How do you test the integration?</h3><p><strong>Test with synthetic data and a question that has a deliberate trap.</strong> The test is useful only if the trap catches a raw-SQL answer and Genie One avoids it.</p><p><strong>1. Build the trap.</strong> Create a demo schema of made-up campaigns and opportunities. Include opportunities that never reached the qualified stage, and some that are duplicated across campaigns. Then define &quot;qualified pipeline&quot; once, in a metric view:</p><pre>CREATE VIEW demo.marketing.pipeline_metrics<br>WITH METRICS<br>LANGUAGE YAML<br>AS $$<br>  version: 1.1<br>  source: demo.marketing.opportunities<br>  joins:<br>    - name: campaigns<br>      source: demo.marketing.campaigns<br>      on: source.campaign_id = campaigns.campaign_id<br>  dimensions:<br>    - name: campaign_name<br>      expr: campaigns.campaign_name<br>    - name: created_quarter<br>      expr: DATE_TRUNC(&#39;QUARTER&#39;, created_date)<br>  measures:<br>    - name: qualified_pipeline<br>      expr: SUM(amount) FILTER (WHERE stage_rank &gt;= 3 AND is_primary_attribution)<br>      comment: Pipeline from opportunities at stage 3 or later, counted once by primary campaign attribution.<br>      synonyms: [qualified pipeline, QP]<br>$$</pre><p>A naive SUM(amount) over the raw table overstates pipeline. That gap is what the test looks for.</p><p><strong>2. Ask the question.</strong> <em>“Which marketing campaigns generated the most qualified pipeline last quarter, and where should we investigate underperformance?”</em></p><p><strong>3. Check the answer:</strong></p><ul><li>The client shows a Genie One tool call (genie_ask or view_ask), not an answer from the model&#39;s general knowledge.</li><li>The Databricks deep link shows that Genie used pipeline_metrics and the previous calendar quarter.</li><li>The figures match a direct MEASURE(qualified_pipeline) query on the metric view.</li><li>A follow-up such as <em>“Break that down by region”</em> keeps the same conversation_id.</li></ul><p><strong>What the trap shows.</strong> I built a 12-row synthetic dataset for Q3 2026: four made-up campaigns and ten opportunities. Two opportunities are each attributed to two campaigns. I ran the naive sum and the metric-view definition side by side in Databricks SQL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CHJRT2lRHrB9ZnYs3LMpWA.png" /></figure><p>The naive sum overstates qualified pipeline by <strong>2.45×</strong>, and it changes the answer to the business question. By raw amount, Webinar Series looks like the top campaign. By qualified pipeline, Partner Event leads. Content Syndication looks healthy at $340,000, but $300,000 of that is one opportunity that never got past stage 1. That’s the underperformance a marketing lead should look into, and a model writing its own SQL against the raw table would most likely miss it.</p><p>A correct Genie One answer should therefore name <strong>Partner Event</strong> as the leader and flag <strong>Content Syndication</strong> and <strong>Paid Search</strong>, both of which have large amounts of early-stage pipeline. If your client’s answer ranks Webinar Series first, Genie didn’t use the metric view. Check that the metric view is in a schema the caller can read and that its comment and synonyms describe &quot;qualified pipeline.&quot;</p><h3>How do you secure and monitor Genie One MCP?</h3><p>Genie One MCP is governed by the identity, grants, and policies applied through Databricks. Unity Catalog permissions are enforced on requests, so each user or service principal can access only the authorized data.</p><p>For interactive analysis, on-behalf-of user OAuth authentication is recommended. Service-principal authentication can suit automated workloads, but every request using a shared principal operates under that principal’s permissions.</p><p>Follow these controls:</p><ul><li>Grant EXECUTE on the MCP and USE CATALOG and USE SCHEMA on its parents only to the required users and groups.</li><li>Review broad default grants on system.ai.</li><li>Keep secrets and tokens out of source control.</li><li>Test with identities that have different permissions and verify the results.</li><li>Review usage and access logs regularly.</li></ul><p>Databricks records MCP invocations as mcpCall events in system.access.audit. Usage, errors, and latency are available through system.ai_gateway.usage when filtered to service_type = &#39;MCP_SERVICE&#39;.</p><p>For example, this query summarizes calls by tool:</p><pre>SELECT<br>  mcp_metadata.tool_name AS tool_name,<br>  COUNT(*) AS calls<br>FROM system.ai_gateway.usage<br>WHERE service_type = &#39;MCP_SERVICE&#39;<br>  AND service_name = &#39;system.ai.genie_one_mcp&#39;<br>GROUP BY mcp_metadata.tool_name<br>ORDER BY calls DESC;</pre><p>Unity Gateway policies can also allow, block, or require approval for tool calls. These policy features require the applicable Unity Gateway Beta enablement.</p><p>For detailed permissions, policies, and monitoring, see <a href="https://docs.databricks.com/aws/en/ai-gateway/govern-mcp-service">Databricks’ MCP governance guide</a>.</p><h3>When should you use Genie One MCP?</h3><p>Use Genie One MCP when people want natural-language answers to business questions across their workspace and accuracy depends on trusted metrics, relationships, and business definitions.</p><p><strong>A simple rule:</strong> if the person asking would describe the question in business terms (“qualified pipeline,” “net revenue”), use Genie One MCP. If they’d write the SQL themselves, use the Databricks SQL MCP. If one curated domain should answer every question, use the Genie Agent MCP.</p><h3>Key takeaways</h3><ul><li>Genie One MCP connects external AI clients to business-aware analytics rather than unrestricted raw-table access.</li><li>Move legacy integrations to system.ai.genie_one_mcp and the ai-gateway OAuth scope before October 31, 2026.</li><li>Register the correct redirect URLs and test each client independently.</li><li>Validate answers against synthetic data and different access identities.</li><li>Monitor mcpCall events, usage, errors, and latency as part of ongoing governance.</li></ul><h3>Frequently asked questions</h3><ol><li><strong>What is Genie One MCP?</strong><br>Genie One MCP is a Databricks-provided MCP server that exposes Genie One’s conversational analytics capability to compatible AI clients.</li><li><strong>Can ChatGPT, Claude, and Cursor use the same server?</strong><br>Yes. They can connect to the same Genie One MCP endpoint when their client and workspace support the integration, but each may require different configuration and OAuth settings.</li><li><strong>Does MCP bypass Unity Catalog permissions?</strong><br>No. Unity Catalog permissions are enforced on every Genie One MCP request under the effective user’s or service principal’s identity.</li><li><strong>Which authentication and permissions are required?</strong><br>The documented on-behalf-of user OAuth workflow uses the ai-gateway scope. Callers also need EXECUTE on the MCP, USE CATALOG and USE SCHEMA on its parents, workspace assignment, and access to the underlying data.</li><li><strong>How is Genie One MCP different from querying raw tables directly?</strong><br>Genie One MCP routes business questions through Genie One, which uses Genie Ontology to interpret business definitions and relationships. Direct table access leaves more of that interpretation to the external model or developer.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55b811aecfcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Skew in PySpark Join: Part 2 — Solving a Hot Key with Salting]]></title>
            <link>https://medium.com/@jsl.jaisingh/data-skew-in-pyspark-join-part-2-solving-a-hot-key-with-salting-3550f61ed3f2?source=rss-510a7e3982d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3550f61ed3f2</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[pyspark]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-engineer]]></category>
            <dc:creator><![CDATA[Jai Singh]]></dc:creator>
            <pubDate>Mon, 28 Sep 2026 18:11:01 GMT</pubDate>
            <atom:updated>2026-09-28T18:11:01.802Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eol7roAzHdH7QOB5wdTCZg.png" /></figure><h3>A Spark join can become extremely slow when one key contains a disproportionate amount of data.</h3><h3>Consider:</h3><pre>Two tables :<br>orders     (order_id, customer_id, amount)<br>customers  (customer_id, country)</pre><p>Suppose:</p><pre>customer_id = 123 → 50 million orders<br>most other customers → a few thousand orders</pre><p>A normal join:</p><pre>result = orders.join(customers, &quot;customer_id&quot;)</pre><p>can create <strong>data skew</strong> because Spark shuffles rows based on customer_id.</p><pre> customer_id = 123<br>        ↓<br> one shuffle key<br>        ↓<br> one huge partition<br>        ↓<br>   slow task</pre><p>Simply increasing spark.sql.shuffle.partitions does not fundamentally solve this—123 is still one key.</p><h3>Detect the Skew</h3><pre>from pyspark.sql import functions as F<br>orders.groupBy(&quot;customer_id&quot;) \<br>    .count() \<br>    .orderBy(F.desc(&quot;count&quot;)) \<br>    .show(20)</pre><p>Also check the Spark UI for one task having significantly larger shuffle data or execution time.</p><h3>Fix: Salting</h3><p>Create multiple versions of the hot key.</p><pre>(123,0)<br>(123,1)<br>(123,2)<br>...<br>(123,19)</pre><p>Use a deterministic hash of order_id:</p><pre>SALT_BUCKETS = 20<br>orders_salted = orders.withColumn(<br>    &quot;salt&quot;,<br>    F.when(<br>        F.col(&quot;customer_id&quot;) == 123,<br>        F.pmod(<br>            F.xxhash64(&quot;order_id&quot;),<br>            F.lit(SALT_BUCKETS)<br>        ).cast(&quot;int&quot;)<br>    ).otherwise(F.lit(0))<br>)</pre><p>Now the 50M orders for customer 123 are spread across 20 salted keys.</p><h3>Salt the Customer Side</h3><p>The matching customer row must exist for every salt:</p><pre>salt_values = spark.range(SALT_BUCKETS).select(<br>    F.col(&quot;id&quot;).cast(&quot;int&quot;).alias(&quot;salt&quot;)<br>)<br><br>normal_customers = (<br>    customers<br>    .filter(&quot;customer_id != 123&quot;)<br>    .withColumn(&quot;salt&quot;, F.lit(0))<br>)<br>skewed_customer = (<br>    customers<br>    .filter(&quot;customer_id = 123&quot;)<br>    .crossJoin(salt_values)<br>)<br>customers_salted = normal_customers.unionByName(<br>    skewed_customer<br>)</pre><p>Now:</p><pre>customer_id | salt<br>------------|-----<br>123         | 0<br>123         | 1<br>123         | 2<br>...<br>123         | 19</pre><h3>Perform the Salted Join</h3><pre>result = (<br>    orders_salted<br>    .join(<br>        customers_salted,<br>        [&quot;customer_id&quot;, &quot;salt&quot;],<br>        &quot;inner&quot;<br>    )<br>    .drop(&quot;salt&quot;)<br>)</pre><p>Instead of:</p><pre>123 → one huge partition</pre><p>we get:</p><pre>123 + 0  ──► partition<br>123 + 1  ──► partition<br>123 + 2  ──► partition<br>...<br>123 + 19 ──► partition</pre><h3>Why it works</h3><p>Salting <strong>doesn’t reduce the data</strong>. It changes the distribution of the hot key so multiple tasks can process it in parallel.</p><h3>When to use it</h3><p>Use salting when a few keys dominate the data and create clear task stragglers. Before implementing it manually, check whether <strong>AQE skew-join handling</strong> or a <strong>broadcast join</strong> can solve the problem more simply.</p><blockquote><strong><em>Answer:</em></strong><em> “I would identify the hot key, salt the skewed records using a deterministic hash, replicate the corresponding dimension row across the salt range, and join on </em><em>(customer_id, salt). This distributes the hot key across multiple partitions while preserving the correctness of the join.”</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3550f61ed3f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Skew in PySpark: Solving Hot Keys with Salting]]></title>
            <link>https://medium.com/@jsl.jaisingh/data-skew-in-pyspark-solving-hot-keys-with-salting-179e948e058c?source=rss-510a7e3982d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/179e948e058c</guid>
            <category><![CDATA[pyspark]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Jai Singh]]></dc:creator>
            <pubDate>Sat, 26 Sep 2026 18:01:01 GMT</pubDate>
            <atom:updated>2026-09-26T18:01:01.835Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nbzUNBnm97goIwKcjfGWpA.png" /></figure><p><strong>Data skew</strong> occurs when a small number of keys contain a disproportionate amount of data</p><p>Example:</p><pre>country | records<br>--------|--------<br>US      | 9,000,000<br>IN      |   500,000<br>UK      |   300,000<br>DE      |   200,000</pre><p>Now:</p><pre>df.groupBy(&quot;country&quot;).agg(<br>    F.sum(&quot;amount&quot;).alias(&quot;total_amount&quot;)<br>)</pre><p>causes a <strong>shuffle by </strong><strong>country</strong>. All US rows have the same key, so they are sent to the same shuffle partition. That partition becomes much larger than the others, creating a <strong>straggler task</strong>.</p><h3>1. Detect the skew</h3><pre>df.groupBy(&quot;country&quot;) \<br>  .count() \<br>  .orderBy(F.desc(&quot;count&quot;)) \<br>  .show(20)</pre><p>Also check the <strong>Spark UI</strong> for uneven shuffle sizes and one or more tasks taking significantly longer.</p><h3>2. Create a skewed dataset</h3><pre>from pyspark.sql import functions as F<br>df = (<br>    spark.range(10_000_000)<br>    .withColumn(<br>        &quot;country&quot;,<br>        F.when(F.rand(42) &lt; 0.90, &quot;US&quot;)<br>         .when(F.rand(43) &lt; 0.95, &quot;IN&quot;)<br>         .when(F.rand(44) &lt; 0.98, &quot;UK&quot;)<br>         .otherwise(&quot;DE&quot;)<br>    )<br>    .withColumn(&quot;amount&quot;, F.rand(45) * 1000)<br>)</pre><h3>3. The problematic aggregation</h3><pre>result = (<br>    df.groupBy(&quot;country&quot;)<br>      .agg(F.sum(&quot;amount&quot;).alias(&quot;total_amount&quot;))<br>)</pre><p>Increasing:</p><pre>spark.conf.set(&quot;spark.sql.shuffle.partitions&quot;, 1000)</pre><p>does <strong>not fundamentally fix</strong> the hot key.</p><p>US still maps to one grouping key and therefore cannot be naturally distributed across many partitions.</p><h3>4. Fix it with Salting</h3><p>Add a salt bucket to distribute the hot key.</p><pre>SALT_BUCKETS = 20<br>salted_df = df.withColumn(<br>    &quot;salt&quot;,<br>    F.pmod(<br>        F.xxhash64(F.monotonically_increasing_id()),<br>        F.lit(SALT_BUCKETS)<br>    ).cast(&quot;int&quot;)<br>)</pre><p>Now US becomes:</p><pre>US + 0<br>US + 1<br>US + 2<br>...<br>US + 19</pre><p>Instead of one huge group:</p><pre>US → 9M rows</pre><p>you get multiple smaller groups:</p><pre>(US,0) → ~450K<br>(US,1) → ~450K<br>...<br>(US,19) → ~450K</pre><h3>5. Two-stage aggregation</h3><h3>Stage 1 — distribute the work</h3><pre>partial = (<br>    salted_df<br>    .groupBy(&quot;country&quot;, &quot;salt&quot;)<br>    .agg(F.sum(&quot;amount&quot;).alias(&quot;partial_amount&quot;))<br>)</pre><h3>Stage 2 — combine the partial results</h3><pre>final_result = (<br>    partial<br>    .groupBy(&quot;country&quot;)<br>    .agg(F.sum(&quot;partial_amount&quot;).alias(&quot;total_amount&quot;))<br>)</pre><p>The final result is equivalent to the original aggregation.</p><h3>Why it works</h3><h3>Without salting</h3><pre>US<br> │<br> └──────► One partition<br>           9M rows</pre><h3>With salting</h3><pre>US<br> ├── 0 ──► Partition 1<br> ├── 1 ──► Partition 2<br> ├── 2 ──► Partition 3<br> ├── ...<br> └──19 ──► Partition 20</pre><p>The hot key is split across multiple tasks.</p><h3>Complete code</h3><pre>from pyspark.sql import functions as F<br># Skewed data<br>df = (<br>    spark.range(10_000_000)<br>    .withColumn(<br>        &quot;country&quot;,<br>        F.when(F.rand(42) &lt; 0.90, &quot;US&quot;)<br>         .when(F.rand(43) &lt; 0.95, &quot;IN&quot;)<br>         .when(F.rand(44) &lt; 0.98, &quot;UK&quot;)<br>         .otherwise(&quot;DE&quot;)<br>    )<br>    .withColumn(&quot;amount&quot;, F.rand(45) * 1000)<br>)<br># Check skew<br>df.groupBy(&quot;country&quot;).count().orderBy(F.desc(&quot;count&quot;)).show()<br># Add salt<br>salted_df = df.withColumn(<br>    &quot;salt&quot;,<br>    F.pmod(<br>        F.xxhash64(F.monotonically_increasing_id()),<br>        F.lit(20)<br>    ).cast(&quot;int&quot;)<br>)<br># First aggregation<br>partial = (<br>    salted_df<br>    .groupBy(&quot;country&quot;, &quot;salt&quot;)<br>    .agg(F.sum(&quot;amount&quot;).alias(&quot;partial_amount&quot;))<br>)<br># Final aggregation<br>final_result = (<br>    partial<br>    .groupBy(&quot;country&quot;)<br>    .agg(F.sum(&quot;partial_amount&quot;).alias(&quot;total_amount&quot;))<br>)</pre><h3>When to use salting</h3><p>Use salting when:</p><ul><li>One or a few keys dominate the data.</li><li>The skew creates long-running tasks.</li><li>The operation itself is the bottleneck.</li></ul><p>Don’t use it automatically. First check the <strong>data distribution and Spark UI</strong>. For skewed <strong>joins</strong>, Spark’s AQE skew-join handling may already help; salting is an explicit technique when you need to control the distribution yourself.</p><h3>Conclusion</h3><blockquote><strong><em>“I would first identify the hot keys from key-frequency analysis and Spark UI metrics. For a heavily skewed aggregation, increasing shuffle partitions alone won’t solve the problem because all rows for the same key still go to the same partition. I would use salting: add a salt bucket, aggregate by </em></strong><strong><em>(key, salt), then aggregate again by the original key. This distributes the hot key across multiple tasks while preserving the final result.&quot;</em></strong></blockquote><p><strong>Key idea:</strong><br><strong>Salting doesn’t reduce the data — it redistributes a hot key so the work can run in parallel.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=179e948e058c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spark Executor Sizing: Fat vs Thin Executors]]></title>
            <link>https://medium.com/@jsl.jaisingh/spark-executor-sizing-fat-vs-thin-executors-62d415e843c6?source=rss-510a7e3982d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/62d415e843c6</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[Jai Singh]]></dc:creator>
            <pubDate>Thu, 24 Sep 2026 17:46:01 GMT</pubDate>
            <atom:updated>2026-09-24T17:46:01.924Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JILD4vLO59Wy40QIF66cPg.png" /></figure><blockquote><strong><em>Suppose you have the same total cluster resources:</em></strong></blockquote><blockquote><strong><em>Option A:</em></strong><em> 10 executors × 16 CPU cores × 64 GB memory<br></em><strong><em>Option B:</em></strong><em> 40 executors × 4 CPU cores × 16 GB memory</em></blockquote><blockquote><em>Both provide </em><strong><em>160 CPU cores and 640 GB memory</em></strong><em>.</em></blockquote><blockquote><strong><em>How would you decide between fewer large (fat) executors and more small (thin) executors?</em></strong></blockquote><p>The key idea:</p><blockquote><strong><em>Same total resources ≠ same Spark behavior.</em></strong></blockquote><p>How those resources are distributed affects <strong>GC, memory pressure, parallelism, shuffle, failure impact, and overhead</strong>.</p><h3>Fat vs Thin Executors</h3><h3>Fat executors</h3><pre>10 executors<br>× 16 cores<br>× 64 GB</pre><p>Fewer JVMs, but each has substantial CPU and memory.</p><h3>Thin executors</h3><pre>40 executors<br>× 4 cores<br>× 16 GB</pre><p>More JVMs, each smaller.</p><h3>When would I prefer thin executors?</h3><h3>1. Very large distributed workloads</h3><p>When you have many independent tasks and want work spread across more execution units.</p><pre>Large dataset<br>   ↓<br>Many partitions<br>   ↓<br>Many tasks<br>   ↓<br>Many smaller executors</pre><p>Useful for large-scale ETL and distributed processing.</p><h3>2. Large executors are showing GC pressure</h3><p>A very large JVM heap can create expensive garbage collection.</p><pre>Large heap<br>   ↓<br>Many objects<br>   ↓<br>  GC<br>   ↓<br>Long pauses</pre><p>Smaller executors can reduce the size of each JVM and make GC behavior easier to manage.</p><h3>3. Smaller failure domains</h3><p>With 40 executors, losing one executor affects a smaller portion of the application than losing one of 10 large executors.</p><p>This can reduce the amount of work that must be recomputed.</p><h3>When would I prefer fat executors?</h3><h3>1. Tasks require substantial memory</h3><p>For example, a large aggregation or memory-intensive transformation may need a significant amount of memory per executor.</p><pre>Large task<br>   ↓<br>Large working set<br>   ↓<br>Needs more executor memory</pre><p>Making executors too small can lead to OOMs or excessive spilling.</p><h3>2. CPU-heavy workloads</h3><p>Suppose:</p><pre>CPU utilization     → 95%<br>Network utilization → 25%<br>Disk I/O             → 15%</pre><p>The workload is primarily computation.</p><p>Larger executors can be worth evaluating because you are concentrating more compute into each execution unit.</p><h3>3. Too many small executors create overhead</h3><p>Extremely small executors can mean:</p><pre>More JVMs<br>→ more scheduling<br>→ more connections<br>→ more management overhead</pre><p>So <strong>thin doesn’t mean infinitely thin</strong>.</p><h3>What about shuffle?</h3><p>Don’t use this rule:</p><blockquote><strong><em>“Heavy shuffle = fat executors.”</em></strong></blockquote><p>Instead ask:</p><p><strong>What is limiting the shuffle?</strong></p><h3>Network-bound shuffle</h3><pre>CPU     → 40%<br>Network → 95%</pre><p>More distributed resources may help because aggregate network capacity can become important.</p><h3>Memory/CPU-bound shuffle</h3><pre>CPU     → 95%<br>Memory  → 90%<br>Network → 50%</pre><p>Larger executors may be worth evaluating.</p><p>So:</p><blockquote><strong><em>Shuffle-heavy does not automatically mean fat or thin executors.</em></strong></blockquote><h3>Practical Example: S3 → Bronze</h3><p>Suppose:</p><pre>S3<br> ↓<br>100,000 CSV files<br> ↓<br>Spark<br> ↓<br>Delta Bronze</pre><p>The job mostly performs:</p><pre>Read → parse → write</pre><p>This is primarily an <strong>I/O and distributed processing</strong> workload.</p><p>I’d generally start with <strong>reasonably sized executors</strong>, not extremely fat executors.</p><p>The goal is to process many files efficiently without creating oversized JVMs.</p><h3>What I Would Monitor</h3><p><strong>Metric — What it tells you</strong></p><p>CPU utilization — Whether CPU is the bottleneck</p><p>GC time — Whether large JVMs or object creation are causing garbage-collection pressure</p><p>Executor memory — Whether executors are under memory pressure</p><p>Spill to disk — Whether execution memory is insufficient</p><p>Shuffle read/write — How much data is moving between stages</p><p>Task duration — Potential parallelism, skew, or slow-task issues</p><p>Executor failures — OOMs, instability, or other executor-level problems</p><h3>Practical Decision Guide</h3><p><strong>Workload characteristic — Starting point</strong></p><p>Large distributed ETL — Thin / moderate executors</p><p>Many partitions and tasks — Thin / moderate executors</p><p>High GC / very large JVMs — Smaller executors</p><p>Large per-task memory requirement — Fat executors</p><p>CPU-heavy processing — Fat executors can be evaluated</p><p>Excessive executor / scheduling overhead — Larger executors</p><p>Network-bound shuffle — More distributed resources may help</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62d415e843c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spark Cluster Sizing]]></title>
            <link>https://medium.com/@jsl.jaisingh/spark-cluster-sizing-c66360d022ee?source=rss-510a7e3982d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c66360d022ee</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Jai Singh]]></dc:creator>
            <pubDate>Tue, 22 Sep 2026 16:26:20 GMT</pubDate>
            <atom:updated>2026-09-22T16:26:20.100Z</atom:updated>
            <content:encoded><![CDATA[<h3>Spark Cluster Sizing: When Should You Use More Small Nodes vs Fewer Large Nodes?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E-KDX7n29E_Qz3ExypkKQA.png" /></figure><blockquote><strong><em>Suppose you have two Spark clusters with the same total compute capacity:</em></strong></blockquote><blockquote><strong><em>Cluster A:</em></strong><em> 100 nodes × 10 CPU cores per node<br></em><strong><em>Cluster B:</em></strong><em> 5 nodes × 200 CPU cores per node</em></blockquote><blockquote><em>Assuming memory, network, storage, and all other parameters are comparable, </em><strong><em>how would you decide which cluster architecture is more appropriate for a given Spark workload?</em></strong></blockquote><p>At first glance, both clusters have:</p><p><strong>1,000 CPU cores</strong></p><p>So, should they perform the same?</p><p><strong>No.</strong></p><p>In Spark, <strong>where those cores are located</strong> matters almost as much as how many cores you have.</p><p>The practical question is not:</p><p><em>“Which cluster has more CPU?” </em>Both have the same CPU.</p><p>The real question is:</p><blockquote><strong><em>Does my workload benefit from distributing work across many machines, or from concentrating compute and memory on fewer machines?</em></strong></blockquote><h3>First, understand the two architectures</h3><h3>Cluster A — many smaller nodes</h3><pre>100 nodes × 10 cores</pre><p>Conceptually:</p><pre>Node 1   → 10 cores<br>Node 2   → 10 cores<br>Node 3   → 10 cores<br>...<br>Node 100 → 10 cores</pre><p>This gives you a highly distributed system.</p><p>You have many machines independently providing:</p><ul><li>CPU</li><li>memory</li><li>network bandwidth</li><li>disk I/O</li><li>task slots</li></ul><h3>Cluster B — few large nodes</h3><pre>5 nodes × 200 cores</pre><p>Conceptually:</p><pre>Node 1 → 200 cores<br>Node 2 → 200 cores<br>Node 3 → 200 cores<br>Node 4 → 200 cores<br>Node 5 → 200 cores</pre><p>Now compute is much more concentrated.</p><p>Each machine has a large amount of CPU and, typically, larger memory capacity as well.</p><p>That can be useful for workloads where <strong>local resources and locality matter more than extreme distribution</strong>.</p><h3>The biggest misconception: “More shuffle means use larger nodes”</h3><p>This is <strong>not necessarily true</strong>.</p><p>A common answer is:</p><blockquote><em>“This is a shuffle-heavy workload, so I’ll use fewer larger nodes.”</em></blockquote><p>That’s incomplete.</p><p>A shuffle involves:</p><pre>Map tasks<br>   ↓<br>Shuffle write<br>   ↓<br>Network transfer<br>   ↓<br>Shuffle read<br>   ↓<br>Reduce tasks</pre><p>If the main bottleneck is <strong>network throughput during shuffle</strong>, having more nodes can actually help because you have more network endpoints and potentially more aggregate network bandwidth.</p><p>So:</p><blockquote><strong><em>Shuffle-heavy ≠ automatically Cluster B</em></strong></blockquote><p>You need to understand <strong>what is limiting the workload</strong>.</p><h3>When would I choose Cluster A?</h3><h3>1. Large-scale ingestion from S3/ADLS</h3><p>This is one of the most practical examples.</p><p>Suppose you have:</p><pre>S3<br> ├── file001.csv<br> ├── file002.csv<br> ├── file003.csv<br> ├── ...<br> └── file100,000.csv</pre><p>Your pipeline is:</p><pre>S3<br> ↓<br>Spark<br> ↓<br>minimal transformation<br> ↓<br>Delta Bronze</pre><p>This workload is largely about:</p><ul><li>reading files</li><li>parsing data</li><li>moving data</li><li>writing data</li></ul><p>It’s heavily influenced by <strong>I/O and parallelism</strong>.</p><p>Cluster A:</p><pre>100 nodes × 10 cores</pre><p>can distribute file processing across many machines.</p><p>For example:</p><pre>Node 1   → files 1–500<br>Node 2   → files 501–1000<br>Node 3   → files 1001–1500<br>...</pre><p>You potentially get more aggregate:</p><ul><li>network bandwidth</li><li>S3/ADLS read throughput</li><li>disk throughput</li><li>distributed processing capacity</li></ul><h3>2. Very large datasets with high parallelism</h3><p>Suppose you’re processing:</p><pre>100 TB of data</pre><p>and your Spark job has tens of thousands of partitions.</p><p>You naturally have many independent tasks:</p><pre>Partition 1 → Task 1<br>Partition 2 → Task 2<br>Partition 3 → Task 3<br>...<br>Partition 50,000 → Task 50,000</pre><p>Cluster A gives Spark many machines across which those tasks can be distributed.</p><p>This is especially useful when you’re trying to scale <strong>distributed work</strong>, not just CPU.</p><h3>3. Distributed I/O is the bottleneck</h3><p>Suppose Spark is doing:</p><pre>S3 → Spark → Delta</pre><p>and Spark’s CPU utilization is only 30%, but network throughput is already near its limit.</p><p>Your problem is not:</p><blockquote><em>“I need more CPU.”</em></blockquote><p>Your problem is:</p><blockquote><em>“I need more aggregate I/O capacity.”</em></blockquote><p>Adding more appropriately sized nodes can increase the number of network and storage paths available to the workload.</p><p>In this situation, Cluster A can be a better starting point.</p><h3>4. Fault isolation matters</h3><p>Consider a simplified example.</p><p>Cluster A:</p><pre>100 nodes</pre><p>If one node fails:</p><pre>1 / 100 ≈ 1% of nodes affected</pre><p>Cluster B:</p><pre>5 nodes</pre><p>If one node fails:</p><pre>1 / 5 = 20% of nodes affected</pre><p>The exact workload impact depends on Spark’s scheduling and workload characteristics, but the principle is important:</p><blockquote><strong><em>Larger nodes create larger failure domains.</em></strong></blockquote><p>This is another reason highly distributed workloads may favor more moderate-sized workers.</p><h3>When would I choose Cluster B?</h3><p>Now let’s look at the opposite situation.</p><h3>1. CPU-heavy processing with relatively little I/O</h3><p>This is one of the clearest examples.</p><p>Imagine:</p><pre>100 GB input<br>↓<br>complex computation<br>↓<br>10 GB output</pre><p>The job might spend most of its time doing calculations.</p><p>For example:</p><ul><li>complex parsing</li><li>expensive mathematical transformations</li><li>cryptographic operations</li><li>CPU-intensive feature engineering</li><li>computationally expensive UDF logic</li><li>certain ML preprocessing workloads</li></ul><p>Conceptually, your cluster might look like:</p><pre>CPU utilization     → 95%<br>Network utilization → 20%<br>Storage I/O         → 15%</pre><p>The bottleneck is CPU.</p><p>In a workload like this, fewer large nodes can be a reasonable architecture because each node has substantial compute and memory available locally.</p><p>The important point is:</p><blockquote><strong><em>You are not choosing Cluster B because it has more CPU. Both clusters have 1,000 cores. You are choosing it because the workload benefits from concentrating that compute.</em></strong></blockquote><h3>2. Very large per-node memory requirements</h3><p>Consider a workload where an individual processing stage needs a very large amount of memory.</p><p>For example:</p><pre>One processing unit needs:<br>150 GB memory</pre><p>A collection of small nodes may make that difficult or inefficient.</p><p>A larger node can provide:</p><pre>Node<br> ├── large memory<br> ├── many CPU cores<br> └── high local resources</pre><p>This can be useful for workloads involving:</p><ul><li>large in-memory state</li><li>large cached datasets</li><li>memory-intensive algorithms</li><li>large aggregations</li><li>certain ML workloads</li></ul><p>The important concept is:</p><blockquote><strong><em>Some workloads need resources together, not merely in aggregate.</em></strong></blockquote><p>Having 1 TB of memory spread across 100 nodes is not equivalent to having 1 TB available on one large node when a single computation needs a very large contiguous working set.</p><h3>3. Workloads that benefit from locality</h3><p>Suppose your workload repeatedly processes data and can keep useful state or cached data on the same machine.</p><p>For example:</p><pre>Read data<br>   ↓<br>Transform<br>   ↓<br>Transform again<br>   ↓<br>Transform again</pre><p>If the workload benefits from keeping data close to the CPU doing the work, reducing movement between machines can help.</p><p>Fewer larger nodes can sometimes reduce cross-node communication.</p><p>This is particularly relevant for workloads where communication between processing components is substantial.</p><h3>4. Communication-heavy workloads</h3><p>Imagine processing where components frequently need to exchange data:</p><pre>Executor A<br>   ↕<br>Executor B<br>   ↕<br>Executor C<br>   ↕<br>Executor D</pre><p>When communication frequently crosses node boundaries, network latency and bandwidth become important.</p><p>If more of the communication can remain within a machine, fewer larger nodes may be beneficial.</p><p>Again, this depends heavily on the workload and the actual network architecture.</p><h3>But what about a huge shuffle?</h3><p>This is where things get interesting.</p><p>Suppose you have:</p><pre>SELECT customer_id, SUM(amount)<br>GROUP BY customer_id</pre><p>with billions of records.</p><p>That’s a shuffle-heavy workload.</p><p>You might think:</p><blockquote><em>“I’ll use Cluster B because each node is huge.”</em></blockquote><p>But the correct answer is: <strong>Measure the bottleneck.</strong></p><h3>Case 1 — network is the bottleneck</h3><pre>CPU     → 40%<br>Memory  → 50%<br>Network → 95%</pre><p>You’re network-bound.</p><p>More distributed nodes may provide more aggregate network capacity.</p><p><strong>Cluster A may be advantageous.</strong></p><h3>Case 2 — CPU/memory is the bottleneck</h3><pre>CPU     → 95%<br>Memory  → 90%<br>Network → 40%</pre><p>Now the workload is compute/memory constrained.</p><p>Larger nodes may make sense.</p><p><strong>Cluster B may be worth evaluating.</strong></p><p>So the correct interview answer is not:</p><blockquote><em>“Shuffle → Cluster B.”</em></blockquote><p>It’s:</p><blockquote><strong><em>“I would identify whether the shuffle is CPU-, memory-, disk-, or network-bound before selecting the node shape.”</em></strong></blockquote><h3>A practical workload-to-cluster mapping</h3><p><strong>Cluster A — More nodes, fewer cores/node</strong></p><ul><li>S3/ADLS ingestion</li><li>Large Bronze ingestion</li><li>Distributed scans</li><li>Network-heavy workloads</li><li>High distributed I/O</li></ul><p><strong>Cluster B — Fewer nodes, more cores/node</strong></p><ul><li>CPU-heavy transformations</li><li>Large per-node memory requirements</li><li>Communication/locality-sensitive workloads</li><li>Large cached or iterative workloads</li></ul><p>These are <strong>starting points</strong>, not absolute rules.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c66360d022ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bloom Filters in Apache Spark]]></title>
            <link>https://medium.com/@jsl.jaisingh/bloom-filters-in-apache-spark-505bf125400b?source=rss-510a7e3982d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/505bf125400b</guid>
            <category><![CDATA[big-data-analytics]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Jai Singh]]></dc:creator>
            <pubDate>Fri, 18 Sep 2026 19:53:56 GMT</pubDate>
            <atom:updated>2026-09-18T19:53:56.397Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Reduce Shuffle Before a Massive Join</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f9P_XEPWe9fvTrzoxV73cg.png" /><figcaption>Bloom filter</figcaption></figure><p>A large join in Spark can become expensive for one simple reason: <strong>too much data moves across the network</strong>.</p><p>Consider this common pattern:</p><pre>result_df = large_df.join(<br>    small_df,<br>    on=&quot;user_id&quot;,<br>    how=&quot;inner&quot;<br>)</pre><p>At first glance, the solution seems obvious: one table is large, the other is small, so join them.</p><p>But what happens when:</p><ul><li>large_df contains billions of rows,</li><li>small_df contains only a few million relevant keys,</li><li>the join is not suitable for broadcasting, and</li><li>most rows in large_df have <strong>no matching </strong><strong>user_id</strong>?</li></ul><p>Spark may end up shuffling a large amount of data that will ultimately be discarded.</p><p>This is where <strong>Bloom-filter-based runtime filtering</strong> becomes interesting.</p><h3>First: What exactly is a Bloom filter?</h3><p>A Bloom filter is a <strong>compact probabilistic data structure used for membership testing</strong>.</p><p>It answers a question like:</p><blockquote><em>“Could this value exist in this set?”</em></blockquote><p>The answer has only two possibilities:</p><pre>FALSE → definitely NOT present<br>TRUE  → MAYBE present</pre><p>That distinction is critical.</p><p>A Bloom filter can have <strong>false positives</strong>, but it cannot have false negatives.</p><h3>Example</h3><p>Suppose our small dataset contains:</p><pre>1001<br>1002<br>1003<br>1004<br>1005</pre><p>A Bloom filter built from these values might produce:</p><pre>1001 → TRUE<br>1002 → TRUE<br>1003 → TRUE<br>9999 → FALSE<br>8888 → FALSE<br>7777 → TRUE</pre><p>7777 → TRUE does <strong>not</strong> mean that 7777 actually exists.</p><p>It means:</p><blockquote><em>“7777 might exist.”</em></blockquote><p>The actual data must still be checked.</p><p>This makes Bloom filters extremely useful for <strong>filtering out values that definitely cannot match</strong>, without requiring an expensive exact lookup for every value.</p><h3>Why is this useful for a Spark join?</h3><p>Consider:</p><pre>large_df = 1 billion rows<br>small_df = 5 million keys<br>Only 50 million large_df rows can possibly match</pre><p>Without filtering:</p><pre>large_df<br><br>1B rows<br>   │<br>   ▼<br>Shuffle<br>   │<br>   ▼<br>Join<br>   │<br>   ▼<br>50M matches</pre><p>The expensive part is that a huge amount of data participates in the shuffle even though most rows ultimately have no match.</p><p>With Bloom-filter-based runtime filtering:</p><pre>small_df<br>   │<br>   ▼<br>Bloom Filter<br>   │<br>   ▼<br>large_df<br>   │<br>   ├── definitely no match → discard<br>   │<br>   └── might match<br>          │<br>          ▼<br>       Shuffle<br>          │<br>          ▼<br>        Join</pre><p>The Bloom filter is therefore a <strong>pre-filter</strong>. It does not replace the join.</p><h3>Spark already supports this optimization</h3><p>This is important: <strong>you normally do not need to write your own Bloom-filter implementation for a Spark join</strong>.</p><p>Spark’s optimizer can attempt to inject a runtime Bloom filter when one side of a shuffle join is selective, with the objective of reducing shuffle data. The feature is controlled by:</p><pre>spark.sql.optimizer.runtime.bloomFilter.enabled</pre><p>So the production approach is:</p><pre>result_df = large_df.join(<br>    small_df,<br>    &quot;user_id&quot;,<br>    &quot;inner&quot;<br>)</pre><p>and let Spark’s optimizer decide whether runtime filtering is worthwhile.</p><h3>Manual demonstration with Spark SQL</h3><p>Spark also exposes Bloom-filter functions such as:</p><pre>bloom_filter_agg()<br>might_contain()</pre><p>Spark’s source contains tests for both functions, including use of a Bloom filter produced by bloom_filter_agg() inside a might_contain() expression.</p><p>For demonstration purposes:</p><pre>small_df.createOrReplaceTempView(&quot;small_users&quot;)<br>large_df.createOrReplaceTempView(&quot;large_users&quot;)</pre><h3>Step 1 — Build the Bloom filter from the small side</h3><pre>bloom_df = spark.sql(&quot;&quot;&quot;<br>    SELECT bloom_filter_agg(<br>        CAST(user_id AS BIGINT),<br>        CAST(100 AS BIGINT),<br>        CAST(1024 AS BIGINT)<br>    ) AS bloom_filter<br>    FROM small_users<br>&quot;&quot;&quot;)</pre><p>Conceptually:</p><pre>small_users<br>   │<br>   │ user_id<br>   ▼<br>Bloom Filter</pre><h3>Step 2 — Use it to identify candidate rows</h3><pre>candidate_df = spark.sql(&quot;&quot;&quot;<br>    SELECT *<br>    FROM large_users<br>    WHERE might_contain(<br>        (<br>            SELECT bloom_filter_agg(<br>                CAST(user_id AS BIGINT),<br>                CAST(100 AS BIGINT),<br>                CAST(1024 AS BIGINT)<br>            )<br>            FROM small_users<br>        ),<br>        CAST(user_id AS BIGINT)<br>    )<br>&quot;&quot;&quot;)</pre><p>Now:</p><pre>                   large_users<br>                        │<br>                        ▼<br>                  might_contain()<br>                        │<br>                    ┌───┴───────────────┐<br>                    │                   │<br>                  FALSE               TRUE<br>                    │                   │<br>                    ▼                   ▼<br>                  discard          candidate</pre><h3>Step 3 — Perform the actual join</h3><pre>result_df = candidate_df.join(<br>    small_df,<br>    &quot;user_id&quot;,<br>    &quot;inner&quot;<br>)</pre><p>This last step is essential.</p><p>If the Bloom filter produces a false positive:</p><pre>7777 → TRUE</pre><p>but 7777 does not exist in small_df, the actual join removes it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=505bf125400b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Python UDFs Are Slow in Spark: What Actually Happens Behind the Scenes]]></title>
            <link>https://medium.com/@jsl.jaisingh/why-python-udfs-are-slow-in-spark-what-actually-happens-behind-the-scenes-e63b11158cd9?source=rss-510a7e3982d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/e63b11158cd9</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Jai Singh]]></dc:creator>
            <pubDate>Sun, 28 Jun 2026 12:11:00 GMT</pubDate>
            <atom:updated>2026-06-28T12:11:00.751Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JsO3QqnAG4OqojQogZiGeg.png" /><figcaption>Python UDF</figcaption></figure><p>Python UDFs are one of the most commonly used features in PySpark.</p><p>They are flexible, easy to write, and useful when Spark’s built-in functions cannot handle a specific business rule. But they are also one of the most common reasons a Spark job becomes slow, expensive, and difficult to scale.</p><p>The usual explanation is:</p><blockquote><em>“Python UDFs are slow because of serialization and deserialization.”</em></blockquote><p>That is true, but incomplete.</p><p>To really understand the performance problem, we need to see where a Python UDF runs and how data moves during execution.</p><h3>First: Python UDFs are still distributed</h3><p>A common misconception is that Python UDFs run in driver memory.</p><p>They do not.</p><p>Spark still distributes the work across partitions and executors. If your DataFrame has many partitions, different executor tasks can process those partitions in parallel.</p><p>The difference is where the Python code runs.</p><p>Spark’s main execution engine runs inside the <strong>executor JVM</strong>. But a Python UDF cannot run directly inside that JVM. Therefore, Spark uses a separate <strong>Python worker process</strong> alongside the executor.</p><p>So, on a worker node, you typically have:</p><ul><li>A Spark executor JVM processing the Spark task</li><li>A Python worker process executing the Python UDF logic</li></ul><p>This is not VM-to-VM communication. It is process-to-process communication, usually within the same worker node.</p><h3>What happens when Spark executes a Python UDF?</h3><p>Consider this simple UDF:</p><pre>from pyspark.sql.functions import udf<br>from pyspark.sql.types import StringType<br><br>@udf(StringType())<br>def clean_city(city):<br>    if city is None:<br>        return None<br>    return city.strip().lower()</pre><p>And then:</p><pre>df = df.withColumn(&quot;clean_city&quot;, clean_city(&quot;city&quot;))</pre><p>Behind the scenes, the following flow happens for each partition:</p><ol><li>Spark executor JVM reads the partition data in Spark’s internal format.</li><li>Spark converts and serializes the required input values.</li><li>The input is sent from the executor JVM to the Python worker process &amp; Python deserializes the input.</li><li>The Python UDF runs on Data.</li><li>Python serializes the result.</li><li>The result is sent back to the executor JVM.</li><li>Spark deserializes and converts the output back into Spark’s internal format.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IB0pmoTMW8QkfsWsAO3iDQ.png" /></figure><p>This JVM → Python → JVM movement is the biggest reason standard Python UDFs are slower than native Spark transformations.</p><h3>The real reasons Python UDFs are slow</h3><h3>1. JVM-to-Python data transfer</h3><p>Spark is primarily a JVM-based engine. Its optimized execution happens in Java and Scala inside the executor JVM.</p><p>A Python UDF introduces another runtime: the Python worker.</p><p>Whenever Spark needs to apply the UDF, input data must cross from the JVM to Python. After execution, the output must cross back from Python to the JVM.</p><p>Even when the 2 processes are on the same machine, this transfer has a cost. At small scale, the overhead may not matter.</p><p>At hundreds of millions of rows, repeated transfer becomes expensive.</p><h3>2. Serialization, deserialization, and type conversion</h3><p>Data cannot simply be passed as raw Spark objects into Python.</p><p>The executor must convert and serialize the input into a transferable representation. Python then deserializes it into Python objects.</p><p>The same process happens again for the output:</p><pre>Spark internal format<br>        ↓<br>Serialize / convert<br>        ↓<br>Python object<br>        ↓<br>Run UDF logic<br>        ↓<br>Serialize output<br>        ↓<br>Convert back to Spark internal format</pre><p>For a standard scalar Python UDF, this overhead can happen repeatedly across a very large number of rows.</p><h3>3. Row-by-row Python execution</h3><p>A normal scalar Python UDF generally processes one logical input row at a time.</p><p>For example:</p><pre>@udf(&quot;int&quot;)<br>def square_number(x):<br>    return x * x</pre><p>If Spark has 100 million rows, Python may need to execute that function logic repeatedly for those values.</p><p>Compare that with a native Spark expression:</p><pre>from pyspark.sql import functions as F<br>df = df.withColumn(&quot;square_number&quot;, F.col(&quot;number&quot;) * F.col(&quot;number&quot;))</pre><p>The native expression stays inside Spark’s optimized execution engine. It avoids the Python worker boundary and can be efficiently executed as part of Sparks&#39; physical plan.</p><h3>4. Catalyst cannot optimize the logic inside your UDF</h3><p>Spark’s Catalyst optimizer understands built-in operations such as:</p><pre>F.when(...)<br>F.lower(...)<br>F.trim(...)<br>F.regexp_extract(...)<br>F.coalesce(...)<br>F.transform(...)</pre><p>Because Spark understands these expressions, it can optimize the query plan around them.</p><p>A Python UDF is different.</p><p>Spark sees something like this:</p><pre>Apply custom Python function to this column</pre><p>But Spark cannot inspect the internal Python code and reason about its business logic.</p><p>For example, Catalyst cannot meaningfully optimize this:</p><pre>@udf(&quot;string&quot;)<br>def normalize_email(email):<br>    return email.strip().lower()</pre><p>But it can optimize the equivalent native Spark expression:</p><pre>df = df.withColumn(<br>    &quot;normalized_email&quot;,<br>    F.lower(F.trim(&quot;email&quot;))<br>)</pre><p>The important distinction is:</p><blockquote><em>Catalyst may still optimize parts of the plan around a Python UDF, but it cannot optimize the internal logic of the UDF itself.</em></blockquote><h3>A practical example</h3><p>Suppose you need to standardize city names.</p><h3>Slower approach: Python UDF</h3><pre>from pyspark.sql.functions import udf<br>from pyspark.sql.types import StringType<br><br>@udf(StringType())<br>def clean_city(city):<br>    if city is None:<br>        return None<br>    return city.strip().lower()<br>df = df.withColumn(&quot;clean_city&quot;, clean_city(&quot;city&quot;))</pre><p>This requires the executor JVM to send city values to Python and receive results back.</p><h3>Better approach: native Spark functions</h3><pre>from pyspark.sql import functions as F<br>df = df.withColumn(<br>    &quot;clean_city&quot;,<br>    F.lower(F.trim(F.col(&quot;city&quot;)))<br>)</pre><p>This stays inside the Spark engine.</p><p>It is easier for Spark to optimize, avoids Python process overhead, and will usually scale much better.</p><h3>What about Pandas UDFs and Arrow UDFs?</h3><p>Python UDFs are not always avoidable.</p><p>Sometimes you need custom Python libraries, domain-specific logic, advanced calculations, or machine learning transformations that cannot be expressed using built-in Spark functions.</p><p>In such cases, consider Pandas UDFs or Arrow-optimized Python UDFs.</p><p>Instead of transferring data one row at a time, these approaches process batches of data using Apache Arrow’s columnar format.</p><p>This reduces the JVM-to-Python transfer overhead significantly.</p><p>However, they are not automatically the best choice for every situation.</p><h3>Final takeaway</h3><p>Python UDFs are not slow because they run on the driver. They are fully distributed across Spark executors.</p><p>They are slow because they introduce a boundary between Spark’s executor JVM and a separate Python worker process.</p><p>Data must move from JVM to Python, be deserialized, processed by Python, serialized again, and sent back to the JVM. On top of that, Spark cannot optimize the internal Python logic as effectively as native Spark expressions.</p><p>The simplest rule to remember is:</p><blockquote><em>Use Python UDFs for logic Spark truly cannot express. For everything else, prefer built-in Spark functions.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e63b11158cd9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RBAC vs ABAC: Practical Examples in Modern Data Platforms]]></title>
            <link>https://medium.com/@jsl.jaisingh/rbac-vs-abac-practical-examples-in-modern-data-platforms-369692811011?source=rss-510a7e3982d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/369692811011</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Jai Singh]]></dc:creator>
            <pubDate>Mon, 08 Jun 2026 17:09:54 GMT</pubDate>
            <atom:updated>2026-06-08T17:09:54.157Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uNpnWk-8s8jxrc1gm69LTw.png" /><figcaption>RBAC VS ABAC</figcaption></figure><p>Access control is not just about who can open a table. It is about who can see what data, under what condition, and at what level of detail.</p><p>A simple way to understand this is through an office building.</p><h3>RBAC: Role-Based Access Control</h3><p>RBAC gives access based on role.</p><p>Office example:</p><pre>Employee      → can enter office<br>Manager       → can enter meeting rooms<br>Finance Team  → can enter finance room<br>IT Admin      → can enter server room</pre><p>Data platform example:</p><pre>ops_team     → can access operations tables<br>finance_team → can access finance tables<br>ml_team      → can access feature tables</pre><h3>RBAC SQL Example</h3><pre>GRANT USE CATALOG ON CATALOG theatre_ops_prod TO `ops_team`;<br>GRANT USE SCHEMA ON SCHEMA theatre_ops_prod.gold TO `ops_team`;<br>GRANT SELECT ON TABLE theatre_ops_prod.gold.staffing_recommendation TO `ops_team`;</pre><p>This means:</p><pre>ops_team can read the staffing_recommendation table.</pre><p>RBAC answers:</p><pre>What is your role?</pre><p>But RBAC alone may not be enough.</p><p>Example: Operations team can access a staffing table, but should they see staff_cost, salary, or customer_email?</p><p>Probably not.</p><h3>ABAC: Attribute-Based Access Control</h3><p>ABAC gives access based on attributes and context.</p><p>Office example:</p><pre>Allow room access only if:<br>user is active<br>AND user belongs to Finance<br>AND access time is within office hours<br>AND room is not restricted</pre><p>Data platform example:</p><pre>user.department = finance<br>user.region = Delhi NCR<br>column.tag = pii<br>column.tag = finance_sensitive<br>environment = prod</pre><p>ABAC answers:</p><pre>Who are you, what are you accessing, and under what condition?</pre><h3>Practical Table Example</h3><p>Assume this Gold table:</p><pre>theatre_ops_prod.gold.staffing_recommendation</pre><p>Columns:</p><pre>theatre_id<br>region<br>show_time<br>forecasted_demand<br>recommended_staff<br>staff_cost<br>customer_email</pre><p>Access rules:</p><pre>Theatre manager → sees only assigned theatre rows<br>Regional manager → sees only assigned region rows<br>Operations team → sees staffing data but not staff_cost<br>Finance team → sees staff_cost<br>ML team → sees features but customer PII is masked</pre><h3>Row-Level Security Example</h3><p>Create a mapping table:</p><pre>CREATE TABLE IF NOT EXISTS theatre_ops_prod.security.user_theatre_mapping (<br>    user_email STRING,<br>    theatre_id STRING<br>);</pre><p>Insert sample access mapping:</p><pre>INSERT INTO theatre_ops_prod.security.user_theatre_mapping VALUES<br>(&#39;amit@company.com&#39;, &#39;T001&#39;),<br>(&#39;priya@company.com&#39;, &#39;T002&#39;);</pre><p>Create row filter function:</p><pre>CREATE OR REPLACE FUNCTION theatre_ops_prod.security.can_access_theatre(input_theatre_id STRING)<br>RETURN EXISTS (<br>    SELECT 1<br>    FROM theatre_ops_prod.security.user_theatre_mapping m<br>    WHERE m.user_email = current_user()<br>      AND m.theatre_id = input_theatre_id<br>);</pre><p>Apply row filter:</p><pre>ALTER TABLE theatre_ops_prod.gold.staffing_recommendation<br>SET ROW FILTER theatre_ops_prod.security.can_access_theatre<br>ON (theatre_id);</pre><p>Now if amit@company.com queries the table, he sees only rows for theatre T001.</p><p>This is Row-Level Security.</p><h3>Column Masking Example</h3><p>Operations team should not see staff_cost.</p><p>Finance team should see it.</p><p>Create masking function:</p><pre>CREATE OR REPLACE FUNCTION theatre_ops_prod.security.mask_staff_cost(cost DECIMAL(18,2))<br>RETURN<br>    CASE<br>        WHEN is_account_group_member(&#39;finance_team&#39;) THEN cost<br>        ELSE CAST(NULL AS DECIMAL(18,2))<br>    END;</pre><p>Apply mask:</p><pre>ALTER TABLE theatre_ops_prod.gold.staffing_recommendation<br>ALTER COLUMN staff_cost<br>SET MASK theatre_ops_prod.security.mask_staff_cost;</pre><p>Finance user sees:</p><pre>staff_cost = 18000</pre><p>Operations user sees:</p><pre>staff_cost = NULL</pre><p>This is Column-Level Security.</p><h3>Tag-Based ABAC Example</h3><p>Instead of manually protecting every table, tag sensitive data.</p><pre>ALTER TABLE theatre_ops_prod.gold.staffing_recommendation<br>ALTER COLUMN customer_email<br>SET TAGS (&#39;pii&#39; = &#39;email&#39;);<br><br>ALTER TABLE theatre_ops_prod.gold.staffing_recommendation<br>ALTER COLUMN staff_cost<br>SET TAGS (&#39;finance_sensitive&#39; = &#39;true&#39;);<br><br>ALTER TABLE theatre_ops_prod.gold.staffing_recommendation<br>SET TAGS (<br>  &#39;domain&#39; = &#39;theatre_ops&#39;,<br>  &#39;data_product&#39; = &#39;staffing_recommendation&#39;,<br>  &#39;sensitivity&#39; = &#39;internal&#39;<br>);</pre><p>Now central policies can be designed like:</p><pre>If column tag = pii,<br>mask it for normal users.<br><br>If column tag = finance_sensitive,<br>show it only to finance_team.<br><br>If user.region != data.region,<br>hide the row.</pre><p>This is ABAC-style governance.</p><h3>Dynamic View Alternative</h3><p>Sometimes teams use secure views instead of direct table filters.</p><pre>CREATE OR REPLACE VIEW theatre_ops_prod.gold.vw_staffing_recommendation_secure AS<br>SELECT<br>    theatre_id,<br>    region,<br>    show_time,<br>    forecasted_demand,<br>    recommended_staff,<br>    CASE<br>        WHEN is_account_group_member(&#39;finance_team&#39;) THEN staff_cost<br>        ELSE NULL<br>    END AS staff_cost<br>FROM theatre_ops_prod.gold.staffing_recommendation<br>WHERE theatre_id IN (<br>    SELECT theatre_id<br>    FROM theatre_ops_prod.security.user_theatre_mapping<br>    WHERE user_email = current_user()<br>);</pre><p>Then give access to the view:</p><pre>GRANT SELECT ON VIEW theatre_ops_prod.gold.vw_staffing_recommendation_secure<br>TO `ops_team`;</pre><p>This is useful when you want a simplified secure serving layer.</p><h3>Final Takeaway</h3><p>Use both.</p><pre>RBAC = who can enter the building<br>RLS  = which room they can enter<br>CLS  = which files they can read<br>ABAC = dynamic rules based on role, department, region, time, and data sensitivity</pre><p>A practical enterprise pattern is:</p><pre>RBAC → baseline access<br>RLS  → row restriction<br>CLS  → column masking<br>ABAC → scalable tag-based governance<br>Audit → monitoring and compliance</pre><p>RBAC gives the foundation &amp; ABAC makes governance scalable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=369692811011" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ADF Connectivity to SQL Server]]></title>
            <link>https://medium.com/@jsl.jaisingh/adf-connectivity-to-sql-server-0034c575e9d5?source=rss-510a7e3982d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/0034c575e9d5</guid>
            <category><![CDATA[azure-data-factory]]></category>
            <category><![CDATA[data-engineering-101]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Jai Singh]]></dc:creator>
            <pubDate>Sun, 07 Jun 2026 11:29:10 GMT</pubDate>
            <atom:updated>2026-06-26T11:08:16.528Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jLHm41MbQJ8jC8HN064oGA.png" /></figure><p>When we design data ingestion pipelines in Azure, one common requirement is:</p><blockquote><em>“How do we connect Azure Data Factory to a SQL database securely? ”</em></blockquote><p>At first, this sounds simple. We create a linked service in Azure Data Factory, provide the database details, test the connection, and start copying data.</p><p>But in real enterprise projects, networking makes this more interesting.</p><p>The source SQL database can be in different places:</p><pre>SQL Server running on an on-premise machine<br>SQL Server installed on an Azure Virtual Machine<br>Azure SQL Database as a managed PaaS service</pre><p>For each case, the network setup can be different.</p><p>The key is to understand when to use:</p><ul><li>Self-hosted Integration Runtime</li><li>Azure Integration Runtime</li><li>Managed Virtual Network</li><li>Private Endpoint</li><li>VNet Peering</li></ul><p>Let’s understand this in a simple way.</p><h3>First, Understand the Basic Components</h3><p>Before comparing the three scenarios, let’s quickly understand the important building blocks.</p><h3>Azure Data Factory</h3><p>Azure Data Factory, or ADF, is mainly an orchestration and data movement service.</p><p>It does not directly sit inside your private network by default. It sends instructions to an Integration Runtime, and that Integration Runtime performs the actual data movement.</p><p>In simple words:</p><blockquote><em>ADF is the brain. Integration Runtime is the worker.</em></blockquote><h3>Integration Runtime</h3><p>Integration Runtime is the compute layer used by ADF to connect to data sources and move data.</p><p>There are different types of Integration Runtime, but for this topic, the most important ones are:</p><pre>Azure Integration Runtime<br>Self-hosted Integration Runtime<br>Azure Integration Runtime with Managed Virtual Network</pre><h3>Self-hosted Integration Runtime</h3><p>Self-hosted Integration Runtime, or SHIR, is installed on a Windows machine.</p><p>This machine can be:</p><ul><li>An on-prem Windows server</li><li>An Azure VM</li><li>A Windows VM inside a private network</li><li>A VM that can reach the source database through VPN or ExpressRoute</li></ul><p>SHIR is used when the data source is inside a private network and ADF cannot directly access it.</p><p>For example:</p><pre>ADF Cloud<br>   |<br>   | Sends copy instruction<br>   ↓<br>SHIR Machine<br>   |<br>   | Connects privately<br>   ↓<br>SQL Server</pre><p>SHIR is not the database. It is not the storage layer. It is simply the worker that helps ADF connect to private sources.</p><h3>Private Endpoint</h3><p>A Private Endpoint is used to connect privately to Azure PaaS services.</p><p>Examples of Azure PaaS services are:</p><ul><li>Azure SQL Database</li><li>Azure Storage Account</li><li>Azure Key Vault</li><li>Azure Cosmos DB</li><li>Azure Synapse</li></ul><p>A Private Endpoint gives a private IP address from your VNet to that Azure service.</p><p>In simple words:</p><blockquote><em>Private Endpoint brings an Azure PaaS service into your private network using a private IP.</em></blockquote><h3>VNet Peering</h3><p>VNet Peering is used to connect two Azure Virtual Networks.</p><p>For example:</p><pre>VNet A: SHIR VM<br>VNet B: SQL Server VM</pre><p>If these two VNets are peered, the SHIR VM in VNet A can communicate with the SQL Server VM in VNet B using private IP connectivity, assuming NSG, firewall, and routing rules allow it.</p><p>In simple words:</p><blockquote><em>VNet Peering connects two Azure networks together.</em></blockquote><h3>Scenario 1: SQL Server Is On-Premise</h3><p>This is a very common enterprise scenario.</p><p>The SQL Server is running inside the company’s own data center, office network, hospital network, banking network, or some private corporate network.</p><p>Example:</p><pre>On-prem Data Center<br>SQL Server installed on a private server</pre><p>In this case, ADF cannot directly connect to the SQL Server because the SQL Server is not publicly exposed.</p><h3>Recommended Setup</h3><p>Use:</p><pre>ADF + Self-hosted Integration Runtime</pre><p>The SHIR should be installed on a Windows machine that can access the on-prem SQL Server.</p><p>This machine can be inside the same on-prem network, or it can be an Azure VM connected to the on-prem network through VPN or ExpressRoute.</p><h3>Network Flow</h3><pre>Azure Data Factory<br>        |<br>        | Sends pipeline instruction<br>        ↓<br>Self-hosted Integration Runtime machine<br>        |<br>        | Connects to SQL Server over private network<br>        ↓<br>On-prem SQL Server<br>        |<br>        | Data copied<br>        ↓<br>ADLS / Blob / target system</pre><h3>Do We Need Private Endpoint Here?</h3><p>Usually, no.</p><p>Private Endpoint is mainly for Azure PaaS services. An on-prem SQL Server is not an Azure PaaS service.</p><p>So for on-prem SQL Server, the usual answer is:</p><blockquote><em>Use SHIR. Install it on a machine that has network connectivity to the on-prem SQL Server.</em></blockquote><h3>Scenario 2: SQL Server Is Installed on an Azure VM</h3><p>This is different from Azure SQL Database.</p><p>Here, SQL Server is manually installed on a Virtual Machine in Azure.</p><pre>Azure VM<br>Windows Server<br>SQL Server installed on it</pre><p>This VM belongs to an Azure Virtual Network.</p><h3>Recommended Setup</h3><p>Use:</p><pre>ADF + SHIR + VNet connectivity</pre><p>Why SHIR?</p><p>Because SQL Server on Azure VM behaves like a private server. It has a private IP inside a VNet. ADF needs a worker machine that can reach it privately.</p><h3>Case 2A: SHIR VM and SQL Server VM Are in the Same VNet</h3><p>This is the simplest setup.</p><pre>Azure Data Factory<br>        |<br>        ↓<br>SHIR VM in VNet-A<br>        |<br>        ↓<br>SQL Server VM in same VNet-A</pre><p>In this case, the SHIR VM and SQL Server VM are in the same Virtual Network.</p><p>They may be in different subnets, but that is fine as long as routing, NSG, and firewall rules allow communication.</p><p>Example:</p><pre>VNet: vnet-prod-data</pre><pre>Subnet 1: shir-subnet<br>SHIR VM: 10.10.1.4</pre><pre>Subnet 2: sql-subnet<br>SQL Server VM: 10.10.2.4</pre><p>This is still valid because both are inside the same VNet.</p><h3>Case 2B: SHIR VM and SQL Server VM Are in Different VNets</h3><p>Sometimes the SHIR VM and SQL Server VM are not in the same VNet.</p><p>Example:</p><pre>VNet-A: SHIR VM<br>VNet-B: SQL Server VM</pre><p>In this case, we need VNet Peering or another private routing mechanism.</p><h3>Network Flow</h3><pre>Azure Data Factory<br>        |<br>        ↓<br>SHIR VM in VNet-A<br>        |<br>        | VNet Peering<br>        ↓<br>SQL Server VM in VNet-B</pre><p>Once the VNets are peered, resources in both VNets can communicate using private IPs, assuming security rules allow it.</p><h3>Do We Need Private Endpoint Here?</h3><p>Usually, no.</p><p>SQL Server on Azure VM is not an Azure PaaS database. It is just SQL Server running inside a VM. The VM already has a private IP in the VNet.</p><h3>Simple Answer</h3><p>If SQL Server is installed on an Azure VM, I would place the SHIR machine in the same VNet or a peered VNet. The SHIR machine should be able to connect to the SQL Server VM using private IP or hostname. I would check NSG rules, Windows firewall, route tables, DNS, and SQL port 1433.</p><h3>Scenario 3: Azure SQL Database</h3><p>Azure SQL Database is different from SQL Server on VM.</p><p>Azure SQL Database is a managed PaaS service. Microsoft manages the underlying infrastructure. We do not manage the VM.</p><p>Example:</p><pre>myserver.database.windows.net</pre><p>Here, we have two common connectivity options.</p><h3>Case 3A: Public Access Is Allowed</h3><p>If Azure SQL Database allows public network access and the firewall allows ADF, then we can use Azure Integration Runtime.</p><h3>Network Flow</h3><pre>Azure Data Factory<br>        |<br>        | Azure Integration Runtime<br>        ↓<br>Azure SQL Database public endpoint</pre><p>In this case, SHIR is usually not required.</p><h3>Simple Answer</h3><p>If Azure SQL Database allows public access, ADF can connect using Azure Integration Runtime. We do not need SHIR unless there is a specific network or security requirement.</p><h3>Case 3B: Public Access Is Disabled and Private Access Is Required</h3><p>In many enterprise projects, public access to Azure SQL Database is disabled.</p><p>In that case, we use Private Endpoint.</p><h3>Recommended Setup</h3><p>Use:</p><pre>ADF Managed VNet + Managed Private Endpoint</pre><p>This allows ADF to connect privately to Azure SQL Database.</p><h3>Network Flow</h3><pre>Azure Data Factory Managed VNet<br>        |<br>        | Managed Private Endpoint<br>        ↓<br>Azure SQL Database Private Endpoint<br>        |<br>        ↓<br>Azure SQL Database</pre><p>This is a clean option because we do not need to manage SHIR VMs.</p><h3>Important Point About DNS</h3><p>For Azure SQL Database with Private Endpoint, DNS is very important.</p><p>Even though the database is reached privately, the connection usually still uses the normal SQL server name like:</p><pre>myserver.database.windows.net</pre><p>DNS should resolve this name to the private endpoint IP.</p><p>If DNS is wrong, the connection may go to the public endpoint or fail.</p><h3>Simple Answer</h3><p>If the source is Azure SQL Database and public access is allowed, I can use Azure Integration Runtime. If public access is disabled and private connectivity is required, I would use Private Endpoint, preferably with ADF Managed VNet and Managed Private Endpoint. SHIR is optional in this case and mainly used if we need a custom worker VM or already have SHIR infrastructure.</p><h3>Simple Rule to Remember</h3><pre>On-prem SQL Server<br>= Use SHIR<br><br>SQL Server on Azure VM<br>= Use SHIR + same VNet or VNet Peering<br><br>Azure SQL Database<br>= Use Azure IR if public access is allowed<br>= Use Private Endpoint / Managed Private Endpoint if private access is required</pre><h3>Final Summary</h3><blockquote><em>The connectivity pattern depends on where the SQL source is hosted. If SQL Server is on-premise, I would use Self-hosted Integration Runtime installed on a Windows machine that can reach the on-prem SQL Server. ADF sends the copy instruction, but SHIR performs the actual connection and data movement.</em></blockquote><blockquote><em>If SQL Server is installed on an Azure VM, I would still use SHIR. The SHIR VM should be in the same VNet or in a peered VNet so that it can connect to the SQL Server VM using private IP or hostname. I would validate NSG, firewall, routing, DNS, and port 1433.</em></blockquote><blockquote><em>If the source is Azure SQL Database, then the approach depends on public or private access. If public access is allowed, Azure Integration Runtime can be used. If public access is disabled, I would use Private Endpoint, preferably through ADF Managed VNet and Managed Private Endpoint. SHIR is optional in this case and is mainly used when we need more control over the worker machine or already have SHIR infrastructure.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0034c575e9d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>