<?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 Or Sagiv on Medium]]></title>
        <description><![CDATA[Stories by Or Sagiv on Medium]]></description>
        <link>https://medium.com/@orsagiv?source=rss-e6d3fd8613b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nw5eqgs6P4yAY8q-EC1dzw.jpeg</url>
            <title>Stories by Or Sagiv on Medium</title>
            <link>https://medium.com/@orsagiv?source=rss-e6d3fd8613b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 23:46:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@orsagiv/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[Airflow with Okta: A Step-by-Step Integration]]></title>
            <link>https://medium.com/riskified-technology/airflow-with-okta-a-step-by-step-integration-3a3d87081445?source=rss-e6d3fd8613b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a3d87081445</guid>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[sso]]></category>
            <category><![CDATA[okta]]></category>
            <dc:creator><![CDATA[Or Sagiv]]></dc:creator>
            <pubDate>Tue, 01 Apr 2025 11:48:32 GMT</pubDate>
            <atom:updated>2025-04-01T12:15:30.803Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XWO1Wm7Qt6AY0r1sByG9yg.png" /></figure><p>During our attempts at Riskified to integrate Airflow with Okta, we went through so many docs (most of them confusing…) that if I had to explain it all, I’d need another blog post just on that.</p><p>So instead of doing that, I’ll give you a step-by-step guide on how to do it right.</p><h3>Why Integrate with Okta?</h3><p>Integrating your organization’s applications with Okta offers centralized identity management, single sign-on functionality, and robust security features. Okta streamlines user access management, enhances security, and ensures regulatory compliance through detailed audit logs and access reports.</p><h3>Before We Begin: Important Notes</h3><ul><li>We run Airflow v2.5.0 on K8s (initially, we also ran this integration with v.2.3.2).</li><li>Our deployment method is Apache Airflow’s official<strong> </strong>helm-chart.</li><li>To achieve this integration, we collaborated with our IT team who manage our Okta configuration.</li></ul><p>It all began with an innocent, simple, and not very well-documented <a href="https://airflow.apache.org/docs/apache-airflow/2.3.1/security/webserver.html">doc</a> published by Airflow, which shows an example of using team-based Authorization with GitHub OAuth.</p><p>It was pretty obvious to understand what kind of integration they were implementing and what kind of authorization they were trying to achieve. Moreover, it was an official document of Airflow, so we took the chance and tried to implement it for Okta as well.</p><h3>Step-by-Step Guide: Integrating Airflow with Okta</h3><p>Now, I’ll go through the integration process step by step, dividing it into 4 main parts, starting with our prerequisites. Everything here is instructional — a way for you to follow and implement.</p><h3>1. Pre-Requisites Packages</h3><p>Before anything else, ensure you have installed the following packages in your Airflow deployment. For our setup, it was simply a matter of adding RUN commands to our Dockerfile so that it would pip install the following:</p><ol><li>flask-oidc2==1.5.0</li><li>fab-oidc2==0.0.3</li></ol><h3>2. Setting Up WebserverConfig</h3><p>According to Airflow docs -</p><blockquote>A webserver_config.py configuration file is automatically generated and can be used to configure the Airflow to support authentication methods like OAuth, OpenID, LDAP, REMOTE_USER</blockquote><p>To achieve this in a K8s deployment, within the Airflow Helm Chart, you’ll have to override the entire webserver_config.py, which can be done through webserver.webserverConfig.</p><p>Here is an example of our webserverConfig (with comments on the essential steps):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5be6804d25451dd0af34a76f315181b8/href">https://medium.com/media/5be6804d25451dd0af34a76f315181b8/href</a></iframe><p>Now that we’re done with the webserver config, here is an example of a K8s secrets definition from the Helm chart secret section -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c93e6afc5bedbfb33d5daa1ff7e6b2ec/href">https://medium.com/media/c93e6afc5bedbfb33d5daa1ff7e6b2ec/href</a></iframe><p><strong><em>Note:</em></strong></p><p>We also overrode the ingress.web section, which is exposed in the helm chart, to help you set your own org ingress annotations, if any (should differ between organizations).</p><p>Ingress, according to K8s docs:</p><blockquote>Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource.</blockquote><h3>3. Setting Up the Airflow Side</h3><p>By now, you should be able to see this page when first logging into Airflow, and because the Okta group mapped to the Airflow Admin role has been defined (“data-engineering-sg”:[“Admin”]), you already have all of the permissions you need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eDJfEebj1rb_eAY0" /></figure><p>Now that you have set the role mapping in the webserver config, you’ll have to define the roles in Airflow itself so the 2nd side of the mapping can work as expected.</p><p>Go to Airflow -&gt; Security Tab -&gt; List Roles</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1FLO0ktz9f6s2U_G" /></figure><p>Here, you’ll find all of the Airflow default roles, and you’ll need to define the new roles you set on the AUTH_ROLES_MAPPING inside the webserver_config</p><p>This is how to do it:</p><ol><li>Select the ‘User’ role and choose ‘Copy Role’ under the Actions tab.</li><li>Go to the created ‘User copy’ role, and change its name to one of the roles you set in the AUTH_ROLES_MAPPING (e.g. ‘Alpha’).</li><li>Edit this role and <strong>delete</strong> the following permissions (otherwise, all DAGs will be accessible to each individual user):<br>– Can read on DAGs.<br>– Can edit on DAGs.<br>– Can delete on DAGs.</li><li>Do the same for each of the roles you defined in the AUTH_ROLES_MAPPING.</li></ol><h3>4. Use the ‘Access_control’ Parameter Inside Your DAGs Code</h3><p>Now, every logged-in user should already have their own unique role that was created for them. You might ask, how can you connect individual DAG(s) to a specific role(s)?</p><p>As described in the Airflow DAG model source code:</p><blockquote>access_control — Specify optional DAG-level actions, e.g., “{‘role1’: {‘can_read’}, ‘role2’: {‘can_read’, ‘can_edit’, ‘can_delete’}}”</blockquote><p>This is the way to set the right permissions for individual DAGs and connect them to their Airflow role(s).</p><p>So, a simple example would be something like the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/247cb0c36d5619f97ca2e058594e23dc/href">https://medium.com/media/247cb0c36d5619f97ca2e058594e23dc/href</a></iframe><p>This example will certainly do the job, but for us, as admins of the Airflow deployment in our organization, we decided to provide a more robust way for our Airflow users, which would make it even easier and also prevent them from making potential syntax errors.</p><p>This was our suggestion — AccessControlManager class that we created for this purpose:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62d931f4efaf0d752310e4496d24fb03/href">https://medium.com/media/62d931f4efaf0d752310e4496d24fb03/href</a></iframe><p>Now, the same DAG definition from earlier would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1c8f82ec42cff1c9cf69843b0484436/href">https://medium.com/media/b1c8f82ec42cff1c9cf69843b0484436/href</a></iframe><p>Finally, the whole integration is complete!</p><p>When a user from the Bravo team, for example, logs into Airflow for the first time, they will automatically be assigned as Bravo role, and the DAG test-okta-integration-dag will be the only DAG they can see and manage.</p><h3>Now, with everything in its proper place, here’s what you can expect:</h3><p>Every user who logs in for the first time gets an Airflow role corresponding to their Okta group, which we mapped in advance, and this mapping will be stored in the database.</p><p>Further, as users create individual DAGs, the DAG will define the Airflow Roles that should have permissions for it based on the user’s preferences (via the access-control feature).</p><p><strong>Troubleshooting</strong></p><ul><li>If a user tries to log in before you set their AUTH_ROLES_MAPPING and/or their Airflow role, they get the default Viewer role with the least amount of permissions. You can either change the user role (via Airflow CLI/UI) or delete the user and let them re-login</li><li>To actually assign an individual DAG to its Airflow role (and hence to its Okta group), the DAG should be successfully created in the dagbag first. However, if the first creation of a DAG contains an import error, the DAG hasn’t been fully created yet, and as a result, the users with the matching role still won’t be able to see the DAG or the import error. Only users with the Admin role can see those import errors.<br>To overcome this, we took the following steps:<br>– We added Github Actions that run pre-checks on the code, for example, Python syntax checks and dagbag checks so that we can notify users in advance regarding possible errors in their code.<br>– We also expose all the Import Errors to one of our internal tools through an HTTP request to the Airflow API. So, all errors will be available to all users regardless of their role</li></ul><p>Now that everything is in place, we proudly serve 20 teams, empowering 150+ users, and orchestrating 400+ DAGs. Our Data Engineers can operate without interruptions, and our developers enjoy complete independence while sticking to all the essential security standards seamlessly integrated through Okta.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a3d87081445" width="1" height="1" alt=""><hr><p><a href="https://medium.com/riskified-technology/airflow-with-okta-a-step-by-step-integration-3a3d87081445">Airflow with Okta: A Step-by-Step Integration</a> was originally published in <a href="https://medium.com/riskified-technology">Riskified Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spark Streaming as a Service]]></title>
            <link>https://medium.com/riskified-technology/spark-streaming-as-a-service-53420d8a857b?source=rss-e6d3fd8613b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/53420d8a857b</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[delta-lake]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[spark-streaming]]></category>
            <dc:creator><![CDATA[Or Sagiv]]></dc:creator>
            <pubDate>Mon, 11 Jul 2022 07:58:42 GMT</pubDate>
            <atom:updated>2025-04-01T11:55:04.496Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hjMqCXcCcNK-kweYKKLFA.png" /></figure><p>In this blog post, I’m going to share our old Spark streaming infrastructure and the burden of managing it, and how we turn it into our own inhouse Spark Streaming as a Service for the whole organization.</p><p>My team’s goal is to provide data infrastructures and self-services that empower a variety of R&amp;D teams’ abilities. Allowing them to scale more easily with fewer levels of dependence, so they can be more data-driven and less dependent on each other.</p><p>By the end of the post, you will have learned what our struggles were at first and how we overcame those challenges, and most significantly, how we ended up serving 15+ teams and running about 60+ individual streams by our users alone.</p><h3>How our journey began</h3><p>I’ll skip the part when the world realizes that event driven architectures are the best fit for modern microservices architectures. I’d rather tell you that we had an enormous number of events(about 1m every minute) that had to be stored, managed, and accessible through a variety of tables for offline and online usages and for multiple teams and services.</p><p>In the beginning, our infrastructure contained a <a href="https://spark.apache.org/docs/latest/running-on-kubernetes.html">Spark on Kubernetes</a> application, with some generic code that allowed running multiple streams on the same Spark application. Each stream has the same source and destination, but different transformations that vary in each team’s business logic and requirements. For that, we provided a set of predefined generic transformations to be used for new streams on demand.</p><p>The configurations for all streams were stored in a large JSON file that looked something like this…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wT-zj-9maSv9jxLD" /></figure><p>Here every object in the JSON array represents a single stream, and every change in that file requires a manual restart to the Spark application cluster in order to reload them.</p><p>In simple words, it forces all active streams to abort their running jobs and start recalculating from their last checkpoint. It also forced our Kubernetes cluster to reallocate a huge amount of resources during pods scheduling(due to deletion and creation of the app).</p><p>As the business and the company started to grow, we began to get a nice amount of requests for creating, changing and deleting streams. In order to manage the volume of requests, we created a regulated process that defined how teams can ask for a ‘stream-request’:</p><ol><li>Create a templated ticket with all the necessary information</li><li>Join our bi-weekly meeting, so we can validate and approve the ticket</li><li>Each ticket is considered as half a day’s work, just to align the stream with all others and create its ‘stream integrations’ (described later)</li></ol><p>A lot of headaches just for requesting a stream, right? The intention was good, we had great infrastructure to drive events inside the organization as users wish, and most importantly, we helped R&amp;D teams to grow and scale more quickly.</p><p>But, I guess some of you’ve already noticed a few big issues that were holding us back from continued growth:</p><ol><li>Teams lack independence &amp; bureaucracy</li><li>Data Engineer’s half a day’s work per stream-request</li><li>Restarting entire Spark application cluster for every new stream-request</li></ol><p>Before I dive into how we solve each of these issues, let’s get some context with a glimpse into our data lake architecture.</p><h3>Our data lake architecture — in a nutshell</h3><p>Note — It’s important to mention that this was our choice for managing our data lake, but sources and destinations can vary from one architecture to another without disturbing the overall solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OfftXnMcr9OOwfP1" /></figure><p>All of our services are driven by structured events enforced by Schema Registry and published to Kafka.</p><p>Our data lake is stored in S3 in Parquet files as Apache Delta<strong> </strong>tables<strong>,</strong> where every stream’s output is a Delta table. All tables are reflected in our data warehouse, Snowflake, and in Databricks through external tables.</p><h4>Our Spark architecture</h4><p>We run Spark on Kubernetes, and use Spark Structured Streaming as our streaming solution.</p><p>We adopted Databricks Medallion Architecture, which takes advantage of their Apache Delta implementation into 3 layers:</p><ol><li>Bronze — raw data from source systems, for persistency</li><li>Silver — filtered, cleaned and augmented</li><li>Gold — Business level aggregates</li></ol><p>Where each layer is a Spark streaming application that runs all of our users’ streams, according to that layer’s essence.</p><p>Last, but not least, we have our stream’s integrations mentioned above.</p><p>Where every stream has the following integrations:</p><ol><li>Airflow scheduled jobs to optimize &amp; vacuum each Delta table, for best querying performance</li><li>Snowflake external tables on our data lake, for easy access to our Delta tables</li><li>Databricks external tables as our second choice for accessing our Delta tables</li></ol><p>Note — The solution applies to each Spark application, meaning each Medallion layer, but to simplify for clarity, we’ll discuss it as if it’s only on one layer</p><h3>Our implementation</h3><h4>Facing bureaucracy</h4><p>To deal with the bureaucracy we created over time and save my team significant work, we developed a service, let’s call it User-Service, to manage all stream configurations in persistent storage and implement a REST API access layer.</p><p>This REST API manages the streams as a resource and exposes CRUD operations above it, so the users are able to manage their streams on their own as a self-service.</p><p>That part was indeed challenging, but very efficient to create. It took away all of the bureaucracy, allowing teams to fulfill their own stream-requests, by making a simple API call to the User-Service (that already validates the request) by themselves.</p><p>Another advantage was to keep all configurations in a database, instead of a giant JSON file. Its editing was easier and better managed, and we were exposed to fewer configuration issues than we used to be (e.g syntax errors, audit logs, transparency with users, etc).</p><h4>Stream integrations</h4><p>Our next major feature was to take care of the stream integrations.</p><p>Every stream request has to create or delete its stream integrations accordingly (i.e Airflow jobs, Snowflake &amp; Databricks external tables), and that’s exactly what we did.</p><p>We integrated with the above inside User-Service, to enable a full end-to-end automation process without any manual intervention from our side. From new stream request to the complete picture with all components in the architecture, as described above.</p><p>This way we saved ourselves lots of repetitive grunt work and time.</p><p>And so, every ‘stream request’ was transactionally built in a way that either the stream is created in the cluster with all of his integrations, or doesn’t exist at all.</p><p>This is what it looks like when putting it together with a UI</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L7C1Bg1txQ_OSklhWOr3gg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a_mYDUxpYf783yla" /></figure><h4>Zero Downtime</h4><p>​​Up until now, it was still necessary to restart the Spark application when users made changes to the streams’ configurations, as the app was only able to reload them on startup time(via User-Service) and was not aware of changes while it’s running.</p><p>In order to reduce the massive burden of restarting the application with every change, we had to come up with a very creative solution. We decided to implement another very lightweight REST API (powered by Akka HTTP) inside the Spark driver, that we called the Management-Service.</p><p>The Management-Service listens to simple start/stop calls, and can actually start and stop active streams (via Spark <em>StreamingQuery</em> API).</p><p>This way we aren’t interrupting the Spark session or the other active streams, meaning that now none of the stream requests coming from the User-Service will ever have to restart the application again, but to pass the request to the management service.</p><p>Worst case, it will call stop and/or start for a single stream, with its stream’s configuration as the request body.</p><p>Let’s see some code snippets -</p><ol><li>Management-Service REST API</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87c2c10dbe4f9c99aec9bbf9da51f7ad/href">https://medium.com/media/87c2c10dbe4f9c99aec9bbf9da51f7ad/href</a></iframe><p>2. Management Streams Handler</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fe1038efe09e3432aaf58ef028f8739/href">https://medium.com/media/9fe1038efe09e3432aaf58ef028f8739/href</a></iframe><p>Now that all parts are in place, let’s demonstrate the entire process of a ‘stream-request’ end-to-end:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JXfrCwyQVq492MMh" /></figure><h3>Our main bottleneck, and how we solved it</h3><p>Lastly, I want to share one of our major bottlenecks, that you might have guessed could happen with the current architecture.</p><p>As the app keeps growing and we keep running more and more new streams on the same Spark application, the one who carries the load is of course the Spark driver. The driver has a very specific job as the coordinator of the app, which is derived (among others) by the number of streams running on it.</p><p>To manage that bottleneck and maintain scalability for future streams, we split up the Spark application into T-shirt sizes, and moved streams to their matching app size according to their throughput (input/sec and process/sec).</p><p>The implementation was such that the User-Service didn’t break its API, and wasn’t aware of that change. Users can still manage streams in the same way, without knowing or worrying about where their streams are running.</p><p>This division allowed us better management and better visibility on each stream and each Spark application, and of course being more scalable when the driver begins to throttle.</p><h3>Wrapping up</h3><p>Happily ever after, we were able to serve 15+ different teams and run a total of 75+ streams (part of them added while writing this post ;)), with minimum effort for both the data engineers and users from R&amp;D teams.</p><p>Thank you for your time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53420d8a857b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/riskified-technology/spark-streaming-as-a-service-53420d8a857b">Spark Streaming as a Service</a> was originally published in <a href="https://medium.com/riskified-technology">Riskified Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>