<?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 Lama Alosaimi on Medium]]></title>
        <description><![CDATA[Stories by Lama Alosaimi on Medium]]></description>
        <link>https://medium.com/@lalosaimi?source=rss-8292967f9a55------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*htklO3R-0ZbfcuXmLC1xsg.png</url>
            <title>Stories by Lama Alosaimi on Medium</title>
            <link>https://medium.com/@lalosaimi?source=rss-8292967f9a55------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 16:31:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lalosaimi/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[Postgresql Processes Roles]]></title>
            <link>https://blog.devgenius.io/postgresql-processes-roles-86046da3c1fc?source=rss-8292967f9a55------2</link>
            <guid isPermaLink="false">https://medium.com/p/86046da3c1fc</guid>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[relational-databases]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[bed]]></category>
            <dc:creator><![CDATA[Lama Alosaimi]]></dc:creator>
            <pubDate>Mon, 12 Oct 2026 19:50:47 GMT</pubDate>
            <atom:updated>2026-10-26T11:18:21.033Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/524/0*PVYoJG_6aPt-rcNt" /></figure><p>PostgreSQL runs as a family of operating-system processes under one parent, the postmaster (postgres). That parent creates shared memory, listens for connections, and forks every other process the cluster needs.</p><p>Each process has a role and a lifetime. Some stay up for the whole life of the server. Some exist only while a session is active. Some appear only during crash recovery or on a replica syncing.</p><p>This article will give you and overview of Postgresql processes and how the database cluster utlize them in order.</p><h3>Postgresql Processes</h3><ol><li>Postmaster: Accepts TCP connections and signal handling. Does not run SQL. It runs from server start until the cluster (instance) is fully down.</li><li>Background Writer: Writes changed data from memory to disk, so a checkpoint has less to flush at once and the disk stays quieter.</li><li>Checkpointer: Flush dirty buffers and record a safe restart point in WAL. It runs on a timer (checkpoint_timeout), when max_wal_size is reached, or at shutdown (graceful kill).</li><li>Wal Writer: Flushes WAL from buffers to pg_wal so commits do not wait on their own write. It runs continuously, on a short cycle (wal_writer_delay).</li><li>IO Worker: PostgreSQL 18 asynchronous I/O. Backends queue reads; these processes perform them. Sequential scans, bitmap heap scans, and vacuum benefit. Started at boot when io_method = worker (the usual default). Count moves with I/O demand. They are among the last to exit on shutdown.</li><li>Autovacuum Launcher: Watches tables for dead tuples and wraparound risk, then forks workers. It does the vacuuming only by spawning workers.</li><li>Autovacuum Worker: VACUUM / ANALYZE in the background, including wraparound. It runs when the launcher decides a table qualifies. Up to autovacuum_max_workers.</li><li>Logical Replication Launcher: Watches subscriptions and starts apply workers. Even with no active subscription, the worker is alive and idle.</li><li>Logical Replication Worker: Applies a subscription’s changes on the subscriber. It runs only if there is an active subscription.</li><li>syslogger: Collects log lines from every process and writes the log files when logging_collector is on.</li><li>Client Backend: SQL session like psql, Dbeaver, pgadmin II.</li><li>Startup: Replays WAL into the data directory until consistency. On a hot standby it keeps replaying. It runs on crash recovery, PITR (point-in-time recovery), and the whole life of a standby. On a primary it exits once recovery ends.</li><li>walsender: On a primary, streams the WAL to the standby or to pg_basebackup. A logical walsender streams decoded changes. It runs per replication connection. It starts life labeled as a client backend, then becomes walsender.</li><li>walreceiver: On a standby, it pulls the WAL from the primary’s walsender and hands it to startup.</li><li>Archiver: Copies completed WAL segments to archive storage.</li><li>walsummarizer: Reads WAL and writes summary files under pg_wal/summaries so pg_basebackup can take an incremental backup.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b22abe143de4e8ce5cf47f7c57299da2/href">https://medium.com/media/b22abe143de4e8ce5cf47f7c57299da2/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c8a441d1b719ea02634a072b3785c36/href">https://medium.com/media/8c8a441d1b719ea02634a072b3785c36/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21198d6f15f627455cb620d3a31fb0a8/href">https://medium.com/media/21198d6f15f627455cb620d3a31fb0a8/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cbEWAIRwbYbW4D9_lkEdMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mrxLJWrKrAJDS92WfDkyzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c-rQfRJyp16aHte8DjpaVg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86046da3c1fc" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/postgresql-processes-roles-86046da3c1fc">Postgresql Processes Roles</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Software Execution Models]]></title>
            <link>https://medium.com/@lalosaimi/software-execution-models-bf9ae753e910?source=rss-8292967f9a55------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf9ae753e910</guid>
            <category><![CDATA[event-loop]]></category>
            <category><![CDATA[execution-model]]></category>
            <category><![CDATA[multithreading]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[parallelism]]></category>
            <dc:creator><![CDATA[Lama Alosaimi]]></dc:creator>
            <pubDate>Fri, 09 May 2025 18:00:20 GMT</pubDate>
            <atom:updated>2025-05-09T18:00:20.389Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C_4QEctN7VrTKCiXew1a5Q.png" /></figure><h3>Concurrency vs Parallelism</h3><p>When building high-performance or responsive applications, especially in modern multi-core environments, understanding execution models is crucial. Two key terms that often cause confusion are <strong>concurrency</strong> and <strong>parallelism</strong>. While they are related, they solve different problems and are implemented differently in programming.</p><h4>1. What Are Execution Models?</h4><p>An execution model describes how tasks are executed in a program — whether they’re run one after another, interleaved, or simultaneously.</p><h4>2. Concurrency</h4><p>Concurrency is about <strong>dealing with</strong> <strong>many tasks at once</strong>, where progress is made on each task <strong>without necessarily executing them at the same time</strong>.</p><p>In concurrent systems, tasks <strong>interleave</strong> — the system <strong>switches</strong> between them, often very quickly, <strong>giving the appearance that they are running simultaneously</strong>.</p><h4>Characteristics</h4><p>- Often single-threaded.<br>- Good for I/O-bound operations (e.g., waiting for files, networks, user input, DB operations).<br>- Does not require multiple cores.</p><h4>Examples</h4><p><strong>Event loop models</strong> like JavaScript’s Node.js or Python’s <strong>asyncio </strong>or<strong> </strong>Python’s<strong> Twisted reactor</strong>.</p><h4>3. Parallelism</h4><p>Parallelism is about <strong>doing many tasks at the same time</strong> (simultaneously), typically by <strong>using multiple CPU cores</strong>.</p><p>Parallelism <strong>requires multiple threads or processes</strong> that are actually executing simultaneously. It’s best suited for <strong>CPU-bound </strong>tasks like computations or data processing.</p><h4>Characteristics</h4><ul><li>Requires multiple CPU cores.</li><li>Often uses threads or processes.</li><li>True parallelism is limited in Python due to the <strong>Global Interpreter Lock (GIL)</strong>.</li></ul><h4>Examples</h4><ul><li>Multiprocessing in Python: Each process runs independently on different cores.</li><li>Multithreading in Java or C++ (true parallelism).</li></ul><h4>4. Which Should You Use?</h4><p>If your program waits on <strong>I/O</strong>, like web requests or file access → use <strong>concurrency</strong> (event loop).<br>If your program does <strong>heavy computation</strong>, like image processing or data crunching → use <strong>parallelism</strong> (multiprocessing, multithreading).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf9ae753e910" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI Agent Example In Python]]></title>
            <link>https://medium.com/@lalosaimi/ai-agent-example-in-python-f616fa2a933a?source=rss-8292967f9a55------2</link>
            <guid isPermaLink="false">https://medium.com/p/f616fa2a933a</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[langgraph]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[groq]]></category>
            <dc:creator><![CDATA[Lama Alosaimi]]></dc:creator>
            <pubDate>Sat, 12 Apr 2025 09:18:56 GMT</pubDate>
            <atom:updated>2025-04-12T09:18:56.009Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*NL2WVzObrMf_ue-5av09Wg.png" /></figure><h4>Building an Intelligent Service Router: A LangGraph-Powered AI Agent</h4><p>In today’s world of microservices and distributed systems, routing user requests to the right service can be challenging. What if we could create an AI agent that understands natural language requests and automatically routes them to the appropriate service? In this article, I’ll walk you through building exactly that using LangGraph, LangChain, and Groq’s powerful language models.</p><p>Consider these common scenarios:</p><ul><li>A user needs urgent medical assistance</li><li>Someone wants to book a spa appointment</li><li>A customer is trying to order food delivery</li></ul><p>Each of these requests needs to be routed to <strong>different services</strong>, with <strong>different parameters</strong> and <strong>payloads</strong>. Traditionally, this would require users to navigate different interfaces or applications. Our solution? <strong>A single AI agent that can understand and route any request appropriately.</strong></p><p>The project is built on several key components:</p><ol><li><strong>LangGraph</strong>: For creating a directed graph workflow that manages the conversation flow</li><li><strong>Groq LLM</strong>: Powering the natural language understanding using the deepseek-r1-distill-llama-70b model</li><li><strong>Streamlit</strong>: Providing a clean, interactive web interface</li><li><strong>Service Registry</strong>: A CSV-based service catalog that defines available services and their requirements</li></ol><p>The agent’s workflow follows a simple but effective pattern:</p><p>START → LLM Call → Tool Node → END</p><p>This workflow is visualized using <strong>GraphViz</strong>, making it easy to understand the agent’s decision-making process.</p><h3>How It Works</h3><h3>1. Service Definition</h3><p>Services are defined in a CSV file with clear specifications:</p><ul><li>Service name</li><li>Endpoint URL</li><li>Required payload structure</li><li>Description</li><li>Required parameters</li></ul><p><strong>Example</strong></p><pre>service_name,description,parameters<br>hospital_service,For medical emergencies,[location]<br>restaurant_service,For food delivery,[items]</pre><h3>2. Intelligent Routing</h3><p>The agent uses a two-step process:</p><ol><li>Understanding: The LLM analyzes user input to determine intent and extract parameters</li><li>Routing: Based on the understanding, it calls the appropriate service with the correct parameters</li></ol><h3>3. State Management</h3><p>The system uses LangGraph’s StateGraph to maintain conversation context and manage the flow between:</p><ul><li>Initial user input</li><li>LLM analysis</li><li>Service calls</li><li>Response handling</li></ul><h3>Key Features</h3><ol><li>Natural Language Understanding: Users can make requests in plain English</li><li>Parameter Extraction: The agent automatically extracts required parameters from conversations</li><li>Service Validation: Built-in checks ensure all required parameters are present</li><li>Flexible Architecture: Easy to add new services via the CSV registry</li><li>Interactive Interface: Clean Streamlit-based chat interface</li></ol><h3>Implementation Highlights</h3><p>The core logic resides in the agent’s decision-making process:</p><pre>def should_continue(state: MessagesState) -&gt; Literal[&quot;tool_node&quot;, &quot;end&quot;]:<br>    &quot;&quot;&quot;Decide if we should continue the loop or stop&quot;&quot;&quot;<br>    last_message = messages[-1]<br>    if last_message.tool_calls:<br>        return &quot;Action&quot;<br>    return END</pre><p>This ensures the agent can handle multi-turn conversations when needed to gather all required information.</p><h3>Real-World Applications</h3><p>This architecture can be applied to various scenarios:</p><ol><li>Healthcare Systems: Routing patients to appropriate medical services</li><li>Customer Service: Directing customer inquiries to specific departments</li><li>Travel Booking: Handling complex travel arrangements</li><li>Emergency Services: Quick routing of emergency calls</li><li>Hospitality: Managing restaurant and spa bookings</li></ol><h3>Getting Started</h3><p>To run this project:</p><pre>poetry install<br>poetry shell<br>poetry run start</pre><ol><li>Set up your Groq API key</li><li>Install GraphViz for workflow visualization</li></ol><h3>Conclusion</h3><p>This project demonstrates how modern AI tools can be combined to create intelligent service routing systems. By leveraging LangGraph, LangChain, and large language models, we can create natural, conversational interfaces for complex service architectures.</p><p>The complete code is available on <a href="https://github.com/lamoboos223/AI-Agent-Demo?tab=readme-ov-file">GitHub</a>, and I encourage you to try it out and adapt it for your own use cases.</p><p>Follow me on <a href="https://sa.linkedin.com/in/lama-alosaimi">Linkedin</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f616fa2a933a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Open Policy Agent (OPA) in Spring Boot]]></title>
            <link>https://medium.com/@lalosaimi/open-policy-agent-opa-in-spring-boot-2d96d70cb947?source=rss-8292967f9a55------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d96d70cb947</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[opas]]></category>
            <category><![CDATA[grpc]]></category>
            <dc:creator><![CDATA[Lama Alosaimi]]></dc:creator>
            <pubDate>Wed, 12 Apr 2023 14:14:16 GMT</pubDate>
            <atom:updated>2023-04-13T22:55:19.699Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article we will see how to implement an <strong>opa </strong>policy and apply in spring boot in <strong>grpc </strong>mode. First let’s take a brief on both of them.</p><p><strong>Open Policy Agent (OPA)</strong> is an open-source tool for policy-based access control. With OPA, you can define policies in a declarative language called <strong>Rego</strong>, and then use OPA to enforce those policies at <strong>runtime</strong>. OPA can be integrated with a variety of platforms and frameworks, making it a flexible and powerful tool for access control.</p><p><strong>gRPC </strong>is an open-source framework for building high-performance, scalable, and interoperable APIs. gRPC uses <strong>Protocol Buffers</strong> as the data format for API messages, and supports a wide range of programming languages and platforms. With gRPC, you can define <strong>service contracts</strong> using Protocol Buffers and then generate client and server code for your desired language and platform.</p><p>In this article, we’ll explore how to use OPA and gRPC together to enforce access control policies in a Spring Boot application. We’ll start by creating a Rego policy that denies access to salary information for unauthorized users, and then build and deploy the policy to an OPA server. Then, we’ll create a gRPC service that allows users to query their own salary information, and use OPA to enforce the access control policy.</p><p>Creating the Rego Policy</p><p>Our access control policy will deny access to salary information for unauthorized users, unless they are the manager of the employee or if they are querying their own salary information. We’ll define this policy in Rego, a declarative language that allows us to express complex access control rules.</p><p>Here’s the Rego policy we’ll use:</p><pre>package httpapi.authz<br><br># bob is alice&#39;s manager, and betty is charlie&#39;s.<br>subordinates := {&quot;alice&quot;: [], &quot;charlie&quot;: [], &quot;bob&quot;: [&quot;alice&quot;], &quot;betty&quot;: [&quot;charlie&quot;]}<br><br>default allow := false<br><br># Allow users to get their own salaries.<br>allow {<br>    input.method == &quot;GET&quot;<br>    input.path == [&quot;finance&quot;, &quot;salary&quot;, input.user]<br>}<br><br># Allow managers to get their subordinates&#39; salaries.<br>allow {<br>    some username<br>    input.method == &quot;GET&quot;<br>    input.path = [&quot;finance&quot;, &quot;salary&quot;, username]<br>    subordinates[input.user][_] == username<br>}</pre><p>This policy defines two rules for allowing access to salary information. The first rule allows access if the user is querying their own salary information, and the second rule allows access if the user is the manager of the employee.</p><p>Building and Deploying the Policy to OPA Server</p><p>Once we have defined our policy, we need to build it using the OPA command-line tool and deploy it to an OPA server. Here are the steps to do this:</p><ol><li>Install the OPA command-line tool by following the instructions on the OPA website.</li><li>Save the Rego policy to a file called policy.rego.</li><li>Build the policy using the OPA command-line tool:</li></ol><pre>$ opa build policy.rego</pre><p>This command will generate a file named <strong>bundle.tar.gz</strong></p><p>Since we’re running opa as docker container we will also run nginx container to mount the bundles from nginx to the opa server.</p><pre>version: &#39;2&#39;<br>services:<br>  opa:<br>    image: openpolicyagent/opa:0.51.0<br>    ports:<br>      - 8181:8181<br>    command:<br>      - &quot;run&quot;<br>      - &quot;--server&quot;<br>      - &quot;--log-format=json-pretty&quot;<br>      - &quot;--set=decision_logs.console=true&quot;<br>      - &quot;--set=services.nginx.url=http://bundle_server&quot;<br>      - &quot;--set=bundles.nginx.service=nginx&quot;<br>      - &quot;--set=bundles.nginx.resource=bundles/bundle.tar.gz&quot;<br>    depends_on:<br>      - bundle_server<br><br>  bundle_server:<br>    image: nginx:1.20.0-alpine<br>    ports:<br>      - 8888:80<br>    volumes:<br>      - ./opa/bundles:/usr/share/nginx/html/bundles</pre><p>Let’s test the policy directly from the opa server as http request.</p><pre>curl --location &#39;http://localhost:8181/v1/data/httpapi/authz&#39; \<br>--header &#39;Content-Type: application/json&#39; \<br>--data &#39;{<br>    &quot;input&quot;: {<br>        &quot;user&quot;: &quot;alice&quot;,<br>        &quot;path&quot;: [&quot;finance&quot;, &quot;salary&quot;, &quot;alice&quot;],<br>        &quot;method&quot;: &quot;GET&quot;<br>    }<br>}&#39;</pre><p>This command sends a test request to the OPA server to check if Alice, an employee, can access her own salary information. The response should be:</p><pre>{&quot;result&quot;:true}</pre><p>Creating the gRPC Service</p><p>Now that we have our policy built and deployed to an OPA server, we can create our gRPC service to allow users to query their own salary information.</p><p>First, we’ll define our gRPC service contract using Protocol Buffers. Here’s the Protocol Buffers definition:</p><pre>syntax = &quot;proto3&quot;;<br><br>option java_package = &quot;com.example.demo&quot;;<br>option java_multiple_files = true;<br><br>service ExampleService {<br>    rpc isAllowedToCheckSalary (ExampleRequest) returns (ExampleResponse);<br>}<br><br>message ExampleRequest {<br>    string currentUser = 1;<br>    string employee = 2;<br><br>}<br><br>message ExampleResponse {<br>    bool isAllowed = 1;<br>}</pre><p>This definition defines a ExampleService with a ExampleRequest method that takes a SalaryRequest message and returns a ExampleResponse message. The ExampleRequest message contains the user and employee IDs which are the user who is asking for the data and the user who’s getting queried, and the ExampleResponse message contains result if thery are allowed to view the salary information of the employee they’re quering.</p><p>To generate the contract from the proto file execute the following command:</p><pre>mvn clean package</pre><p>Next, we’ll implement the ExampleService in Java using the gRPC framework. Here&#39;s the Java implementation:</p><pre>package com.example.demo;<br><br>import java.util.ArrayList;<br>import java.util.List;<br>import java.util.Map;<br><br>import io.grpc.stub.StreamObserver;<br>import net.devh.boot.grpc.server.service.GrpcService;<br>import org.springframework.beans.factory.annotation.Value;<br>import org.springframework.http.HttpEntity;<br>import org.springframework.http.HttpHeaders;<br>import org.springframework.http.HttpMethod;<br>import org.springframework.http.MediaType;<br>import org.springframework.http.ResponseEntity;<br>import org.springframework.web.client.RestTemplate;<br><br>@GrpcService<br>public class ExampleService extends ExampleServiceGrpc.ExampleServiceImplBase {<br><br>  private final RestTemplate restTemplate;<br><br>  @Value(&quot;${opa.url}&quot;)<br>  String opaUrl;<br><br>  @Value(&quot;${opa.path}&quot;)<br>  List&lt;String&gt; opaPath;<br><br>  @Value(&quot;${opa.method}&quot;)<br>  String opaMethod;<br><br>  public ExampleService(RestTemplate restTemplate) {<br>    this.restTemplate = restTemplate;<br>  }<br><br>  @Override<br>  public void isAllowedToCheckSalary(ExampleRequest request,<br>                                     StreamObserver&lt;ExampleResponse&gt; responseObserver) {<br>    List&lt;String&gt; path = new ArrayList&lt;&gt;(opaPath);<br>    path.add(request.getEmployee());<br><br>    OpaRequestBodyDto opaRequestBodyDto = new OpaRequestBodyDto();<br>    opaRequestBodyDto.setUser(request.getCurrentUser());<br>    opaRequestBodyDto.setPath(path);<br>    opaRequestBodyDto.setMethod(opaMethod);<br>    OpaRequestDto opaRequestDto = new OpaRequestDto(opaRequestBodyDto);<br>    HttpHeaders headers = new HttpHeaders();<br>    headers.setContentType(MediaType.APPLICATION_JSON);<br>    headers.add(HttpHeaders.CONTENT_TYPE, &quot;application/json&quot;);<br><br>    HttpEntity&lt;Object&gt; httpEntity = new HttpEntity&lt;&gt;(opaRequestDto, headers);<br><br>    ResponseEntity&lt;OpaResponseDto&gt; responseEntity =<br>        restTemplate.exchange(opaUrl, HttpMethod.POST, httpEntity, OpaResponseDto.class);<br><br>    ExampleResponse response = ExampleResponse.newBuilder()<br>        .setIsAllowed(responseEntity.getBody().getResult().isAllow())<br>        .build();<br><br>    path.clear();<br><br>    responseObserver.onNext(response);<br>    responseObserver.onCompleted();<br>  }<br><br>}</pre><p>In this service file, the user will communicate with Spring Boot via grpc giving it in the contract (a.k.a payload) the currentUser and the employee he want to check their salary. Then the spring boot will communicate with opa server to the proper policy <strong><em>/v1/data/httpapi/authz </em></strong>to get the response if the user is allowed or not. If the user is allowed it should be their some logic to take place if not it should return a proper error message to the user, but that is outside the scope of this article.</p><p>Finally, let’s run the grpc service and connect to it from postman to check the if Charlie can view his own salary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HSkOksDEEpAP98nB.png" /></figure><p>Thank you for reading the article and let’s connect on Github, Linkedin and Twitter. I’d love to hear from you. 💓</p><p>Github repo: <a href="https://github.com/lamoboos223/Spring-Boot-OPA-Example">https://github.com/lamoboos223/Spring-Boot-OPA-Example</a></p><p>Linkedin: <a href="https://sa.linkedin.com/in/lama-alosaimi">https://sa.linkedin.com/in/lama-alosaimi</a></p><p>Twitter: <a href="https://twitter.com/LAMA_ALOSAIMI1">https://twitter.com/LAMA_ALOSAIMI1</a></p><p>All code is done by my dear friend Rawan and I.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d96d70cb947" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Training Yolov8 On Custom Dataset]]></title>
            <link>https://blog.devgenius.io/training-yolov8-on-custom-dataset-d2edae447c9?source=rss-8292967f9a55------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2edae447c9</guid>
            <category><![CDATA[roboflow]]></category>
            <category><![CDATA[yolo]]></category>
            <category><![CDATA[yolov8]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Lama Alosaimi]]></dc:creator>
            <pubDate>Sun, 12 Feb 2023 07:11:15 GMT</pubDate>
            <atom:updated>2023-02-12T07:11:15.193Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*d9bdHmNIjBIU5qBekdM_xw.jpeg" /></figure><p>Yolo is an object detection model, that is able to detect the object on the image and their exact place by drawing a bounding box on the object. Yolo first developed by Joseph Redmon and Ali Farhadi. The first version of yolo released in 2015. In 2021 Ultralytics released Yolov5 which improved the model gradually. and since then Ultralytics continued improving the yolo till this moment when they released Yolov8 which we will use in this article.</p><p>Yolo stands for “You Only Look Once”. Which means it looks to the frame of an image one time and do its calculations. We’re not going to dig more in the math and calculation of the model as this article targets the developers more than the researchers.</p><p>Yolo is like any other model first it needs to be trained on a prepared dataset. And by prepared I mean cleaned, labeled and splitted in a proper way. For example, 75% train | 15% valid | 10% test. But the splitting depends on your dataset size after all. So, that sizing might not work best for your case.</p><p><strong>Dataset</strong></p><p>First we will take a video of parked cars and then upload the video to <a href="https://roboflow.com/">Roboflow</a> for image labeling. Now, follow the steps to create your own labeled dataset in <a href="https://roboflow.com/">Roboflow</a>.</p><ul><li>Create New Project</li></ul><p>select (Explore Solo)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*Q_h4ISaMBP1Ziy1ygR3wTA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*6dc64GHtvOeAw01Xc7IcWA.png" /></figure><p>Now that you created your project, click your project name and select upload button, then new files. Upload a video you have taken already of cars passing by you.</p><p>after uploading the video, you will have the opportunity to remove the frames with no car in it. You should remove those frames because each frame will be considered an input image to your model.</p><p>Now that you’ve upload your video and removed useless frames, You will start to draw the bounding box on the car object. Just left click on the mouse and drag it to the object till you have a complete square box on the object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r0wRkhwLKIaWvbu9KqT9KA.png" /></figure><p>Finally, after annotating (labeling or draw bounding box) your images, you can now send them to your dataset store by clicking next. It will asks you to set the sizing for train/valid/test. You should select what best fits your case. Because my dataset was small, I gave the training the majority of the images.</p><p>Notice the image size in Generate section is <strong>640x640</strong> which will differ from project to another.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dpr1AIfNODktjA4lsYu7Pw.png" /></figure><p>Now to download your labeled dataset locally, click the next buttons on Generate section and it will automatically sends you to versions section where you can download the dataset as <strong>.zip</strong> file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZvJbUutXjO8K-tUKSFE8ag.png" /></figure><p>click on Export button to render the download pop-up, and select the format to Yolov8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gME86kMeYh0y1IGx7tNYiw.png" /></figure><p>Finally, the dataset is prepared, labeled and downloaded locally. Let’s explore the downloaded dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XHblPVpwE5ZUiaOyAATlWw.png" /><figcaption>cars-dataset folder</figcaption></figure><p>The dataset has three directories: <strong>train, test, valid</strong> based on our previous splitting. The data.yaml is the file we care about and we will refer to in the training process. The data.yaml file has the info of the path of the training, testing, validation directories along with the <strong>number of classes</strong> that we need to <strong>override</strong> the yolo output classification. The three directories have the images beside their corresponding labels in the <strong>yolov8 format</strong> as we selected when <strong>exporting</strong> the dataset.</p><p>!! Note</p><p>change the path in the data.yaml file to the absolute path so yolo can easily find them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T3-h_nk1I2LhaVUXSh_Stg.png" /></figure><p><strong>Yolov8</strong></p><p>Yolov8 model exists on <a href="https://github.com/ultralytics/ultralytics">Ultralytics github</a>, clone the project and follow the instructions below to start it.</p><p>there are two ways to start yolov8, the first one is through CLI which we will use in this article. The second one is using python which we will not include in this article but you may follow the steps on how to use it from <a href="https://github.com/ultralytics/ultralytics#python">here</a>.</p><p><strong>CLI</strong></p><p>by default the cli will not work for you, you need to install the required packages to do so. So, let’s do it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07895a0362067060962d63c6b86b2aed/href">https://medium.com/media/07895a0362067060962d63c6b86b2aed/href</a></iframe><p><strong>Training Process</strong></p><p>to start training the yolo execute the following in the ultralytics directory you just cloned.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01445498628030659d9da9d3725415db/href">https://medium.com/media/01445498628030659d9da9d3725415db/href</a></iframe><p>You will print out some metadata along with the model for you to see.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m43EJ0jg6PiINHq0dnWZ0Q.png" /></figure><p>under that you can see each epoch and how good it’s performing.</p><p>I trained for 5 epochs so the model is scoring 0.704 on mAP50 and 0.442 on mAP50–95</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vgMHwB8zVLRCt-HHsraSVA.png" /></figure><p>finally it will print the summary of the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7szoaSaQ_Ptk6_zWq3ckGg.png" /></figure><p>Now let’s test our model on a video of cars passing by …</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b2d17faad368e385256b4886c9b4240/href">https://medium.com/media/3b2d17faad368e385256b4886c9b4240/href</a></iframe><p><strong>results …</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*vg7zOnA4W38BYgHYWsF4ew.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*n86VXGhuLKkhX_Rho01uyw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*zHQcNRJ2I3Yn_sPUFD67yQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*-NX9ml401coydNDMUJCX8Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*VpBpYK4_AbHma-LN_CwERQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*xnhSVQEGeLA2_r-Ws1Rpjg.jpeg" /></figure><p>And with that, the article comes to an end. We have seen how to build a new dataset from scratch, label it, export it to yolov8 format, feed the dataset to the yolov8 model and predict with it.</p><p>Thank you so much for reading this article and please connect with me on Linkedin <a href="https://www.linkedin.com/in/lama-alosaimi/">https://www.linkedin.com/in/lama-alosaimi/</a></p><p>and follow me on twitter <a href="https://twitter.com/LAMA_ALOSAIMI1">https://twitter.com/LAMA_ALOSAIMI1</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2edae447c9" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/training-yolov8-on-custom-dataset-d2edae447c9">Training Yolov8 On Custom Dataset</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HAProxy]]></title>
            <link>https://blog.devgenius.io/haproxy-e5d39ca64a07?source=rss-8292967f9a55------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5d39ca64a07</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[haproxy]]></category>
            <category><![CDATA[reverse-proxy]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Lama Alosaimi]]></dc:creator>
            <pubDate>Sat, 01 Oct 2022 08:01:54 GMT</pubDate>
            <atom:updated>2022-10-02T15:47:01.787Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*Oh8VJsX25V8Q9BaupXPmbg.png" /></figure><p><strong>HAProxy</strong> stands for high availability proxy. It is a free and <a href="https://github.com/haproxy/haproxy">open source</a> software that provides a high availability load balancer between multiple servers and reverse proxy for TCP (Layer 4) and HTTP (Layer 7). It is written in C a low level language, hence it is efficient in terms of processing and RAM usage.</p><p>It is fascinating that haproxy supports both <strong>tcp</strong> and <strong>http</strong> <strong>protocols</strong>, this means you’re able to set up backend clusters/servers for an entire website, or specify different backends based on the content of client requests.</p><p>Some similar softwares to haproxy such as nginx, Gearman, pound, …, etc.</p><p>So if haproxy is “HIGH AVAILABLE” how does control the traffic?</p><p>haproxy has algorithem to control the traffic distribution between the servers which are:</p><p>1- Round robin: It’s simply go around the list of servers one by one like what Sia said in Chandelier song (123 .. 123 drink … 123 .. 123 drink) 🕺🏻.</p><p>2- Least Connection: New requests are assigned to the server having the fewest current connection requests.</p><p>3- Source: New requests are assigned to the server that previously responded to the same client.</p><p>Without further ado let’s get our hands dirty</p><p>Let’s create a simple spring boot web application with 3 endpoints</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ceb01bebb1541852cace3b5794d30037/href">https://medium.com/media/ceb01bebb1541852cace3b5794d30037/href</a></iframe><p>After creating the 3 endpoints create a dockerfile in order to deploy the application on two containers as if they we’re in different servers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67f292acb5519a36f972f49408c73b94/href">https://medium.com/media/67f292acb5519a36f972f49408c73b94/href</a></iframe><p>Build the docker image</p><pre>docker build -t demo-haproxy .</pre><p>deploy the image to <strong>first</strong> container and make it listen to port <strong>8081</strong></p><pre>docker run -d -e SERVER_PORT=8081 -p 8081:8081 demo-haproxy</pre><p>deploy the image to <strong>second</strong> container and make it listen to port <strong>8082</strong></p><pre>docker run -d -e SERVER_PORT=8082 -p 8082:8082 demo-haproxy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*ZDLqAU4HMfUk2ogUJo1_sw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0LDGxT5aH8_1Nf2ILoMl9g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MX1QODb3FxN1i3am-2TYVw.png" /></figure><p>now that we made sure our containers are running properly and the pages are getting served as expected we can get started on the haproxy part.</p><p>install haproxy on you machine</p><pre>brew install haproxy</pre><p>create a configuration file for the haproxy specifying the frontend (the entry point) of the binding and backends.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a84c046c7409d54717977cb3104930e7/href">https://medium.com/media/a84c046c7409d54717977cb3104930e7/href</a></iframe><p>in the configuration file we specified the frontend name to be http as we will load balance on the layer 7. you may choose whatever frontend name you like, just make it meaningful.</p><p>In the fronend you will specify the ip and port you will listen to and the timeout client which is the timeout for the haproxy client not the backend servers. The default algorithem of haproxy is <strong>Round Robin</strong> but since the browser is <strong>stateful</strong> it will use the <strong>previous session connection</strong> and won’t let that Sia’s (123, 123 drink) song happens, so we will make the <strong>mode http</strong> to let it know that we don’t want to use the previous session but create a new one. Finally, the default backends is nothing but a pointer to the backends you define in the configuration file.</p><p>To introduce your servers you need to make <strong>backends</strong> section and in here we created a default on that will hold all the <strong>servers/containers</strong>.</p><p>server <strong>app1</strong> will route traffic to the container that listens on <strong>8081</strong>.</p><p>server <strong>app2</strong> will route traffic to the container that listens on <strong>8082</strong>.</p><p>Let’s fire it up ^_^</p><pre>haproxy -f haproxy.cfg</pre><p>Go to your browser (http:127.0.0.1:80/) and keep refershing the page, the haproxy will <strong>round robin</strong> you between the two containers respectively.</p><p>first try:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JBWiutYkSLzrr9pwM4aDFQ.png" /></figure><p>second try:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ExZqL6catudzLxPGrnDgCw.png" /></figure><p>as you see we managed to balance between the two servers/containers, but let’s recall the application. It had 3 endpoints a welcome endpoint, app1 endpoint and app2 endpoint.</p><p>We will make <strong>welcome endpoint</strong> routed to <strong>both servers</strong> and route the traffic for <strong>app1 endpoint</strong> to container that listens on <strong>port 8081</strong> and route the traffic for <strong>app2</strong> b to container that listens on<strong> port 8082</strong>.</p><p>To do so first let’s create some new backends to the configuration file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9855fc0b60c2cee8fd46c885e52ad79/href">https://medium.com/media/f9855fc0b60c2cee8fd46c885e52ad79/href</a></iframe><p>after creating the backends let’s create an access control list ACL in the frontend to route the traffic based the url path.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35f28e132166ddc31f063cabca98c7cb/href">https://medium.com/media/35f28e132166ddc31f063cabca98c7cb/href</a></iframe><p>now let’s fire it up and check it out</p><pre>haproxy -f haproxy.cfg</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NOGP6EBET4Jt-zQ8fV7wBA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FryZQ5ISxL9C9r49-18IBg.png" /></figure><p>To view the source code (spring boot app + dockerfile + haproxy configuration file) please visit the github repo: <a href="https://github.com/lamoboos223/spring-boot-haproxy">https://github.com/lamoboos223/spring-boot-haproxy</a></p><p>That’s All ^_^</p><p>Thank you so much for reading the story and let’s connect on linkedin: <a href="https://www.linkedin.com/in/lama-alosaimi/">https://www.linkedin.com/in/lama-alosaimi/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5d39ca64a07" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/haproxy-e5d39ca64a07">HAProxy</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Just Ansible It]]></title>
            <link>https://blog.devgenius.io/just-ansible-it-55156e1cdec8?source=rss-8292967f9a55------2</link>
            <guid isPermaLink="false">https://medium.com/p/55156e1cdec8</guid>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[yaml]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Lama Alosaimi]]></dc:creator>
            <pubDate>Fri, 25 Feb 2022 08:23:41 GMT</pubDate>
            <atom:updated>2022-03-14T09:59:09.331Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7ox1feZ5uarHz67w.jpg" /></figure><p>You’ve probably heard about automation and the power that comes with it. Ansible is part of automating stuff on your local machine or to your environment machines.</p><p>So what is Ansible?</p><p>Ansible is an open-source automating tool for provisioning, configuration management, application deployment and infrastructure A.K.A infrastructure as a code (IaC). Ansible was presented to solve the problem of redundant work on multiple servers such as preparing the production virtual machines to java runtime environment, it takes quite a time to prepare it on one machine so what would happen if you needed that on 10+ virtual machines?</p><p>Ansible came to solve that problem with its “playbook” which has tasks to do some action on the target servers e.g.</p><p>task (1) install java.</p><p>task (2) set java to environment path. etc.</p><p>When you start writing your yaml playbook you need to define the tasks you want to do and the target servers which are known as “hosts” ini file and the hosts file usually referred to as “inventory” in the Ansible documentation.</p><p>Ansible comes with built-in tasks for example “git” task where you can clone a repo. And yum, debug, file, sync and so many other built-in tasks are provided in the Ansible getting started documentation. If you have a customized task you can use shell task to for the need you desire.</p><p>Ansible supports conditional actions. If you have web servers you probably want to check if apache is running before you start it, so you can make a condition on the starting apache web server with the condition key “when”.</p><p>In addition to conditions, Ansible supports loops. Either fixed loops or looping through your target servers in the inventory.</p><p>Ansible is agentless. It means that you only need to install it on the host machine and doesn’t need to be installed on your target servers.</p><p>Worth mentioning, Ansible can be used for application deployment but it’s not preferred. To rapidly deploy your application, it’s better to adapt CICD practices and apply the CICD pipelines with Git and CI tools like Jenkins and CD tools like ArgoCD.</p><p>Now I’m taking you for a quick example on how to use Ansible on your localhost using built-in task and customized task with shell scripting.</p><p>First, make sure to install Ansible on your machine. For Linux if you’re using RHEL or CentOS you can run `yum install Ansible` but if you’re Debian run `apt-get install Ansible`.</p><p>For mac run `brew install Ansible`. For windows you should install Cygwin and from the UI install Ansible and Ansible-doc.</p><p>Now that your Ansible environment is ready create a folder with the following files structure:</p><p>- hosts</p><p>- main.yml</p><p>hosts file will hold all the servers you would like to apply tasks on, for the sake of this example we will keep it with localhost only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*zExhcCQEyVNIFHvbGCjDQw.png" /></figure><p>Now to start writing your playbook go to main.yml and define the tasks and which host to apply these tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*jTTOo9EtXJUmPcr1lyyEQA.png" /></figure><p>now our hosts and playbook are completed we can run the play using the following command:</p><p>ansible-playbook main.yml –i hosts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*RC4CfIM7M2iAGQqfr5lHeQ.png" /></figure><p>Now we’ll create a folder called ‘test’ using the built-in task shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*BcQNXK2CQRcZU57eLWPyOQ.png" /></figure><p>And here’s the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*t-G7Mrxb2sU9QC_1j13ocA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*dpddf_rFC2nK3Xmf7rYHTQ.png" /></figure><p>For more resources on getting started on ansible i recommend this article:</p><p><a href="https://spacelift.io/blog/ansible-tutorial">https://spacelift.io/blog/ansible-tutorial</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55156e1cdec8" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/just-ansible-it-55156e1cdec8">Just Ansible It</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OpenID Connect & OAUTH 2.0]]></title>
            <link>https://blog.devgenius.io/openid-connect-oauth-2-0-758529e6f853?source=rss-8292967f9a55------2</link>
            <guid isPermaLink="false">https://medium.com/p/758529e6f853</guid>
            <category><![CDATA[oidc]]></category>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[openid-connect]]></category>
            <category><![CDATA[apigee]]></category>
            <dc:creator><![CDATA[Lama Alosaimi]]></dc:creator>
            <pubDate>Mon, 24 Jan 2022 16:07:38 GMT</pubDate>
            <atom:updated>2022-01-24T18:48:54.214Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*YOREVOVvRW2AfNa_a9i0eg.jpeg" /></figure><p>Before starting to know oidc and oauth 2.0 we need to take a step back and take a look what they are for?</p><p>So, basically oidc and oauth 2.0 are used for identity and access management (IAM). IAM consists of verifying the identity of the user who’s requesting to access the resource and their level of access. So, to verify the user identity we call that process <strong>Authentication</strong> while checking the access level of the user called <strong>Authorization</strong>.</p><p>Some people use authN and authZ interchangeably and that’s not true. Together they make a strong identity and access management, not one replacing the other. Although you can use authZ only for securing microsevices with OAuth 2.0 which we will visit at the end of this story.</p><p><strong>OpenID Connect workflow</strong></p><p>oidc represents the authN while oauth represent authZ. Now oidc works on top of oauth in other words it works before the authorization step occurs.</p><p>as it shows below:</p><ol><li>user tries to login to a website via <strong>social login (sso)</strong></li><li>the website (client or relay party) will redirect the user to the oidc sso with a <strong>callback</strong> url</li><li>the user enter their credentials</li><li>the oidc endpoint <strong>(/auth) </strong>authenticates the user and send <strong>authorization code</strong> to the website page</li><li>the website send to oidc endpoint <strong>(/token)</strong> the authorization code with the preferred <strong>scope</strong> in exchange of <strong>id token</strong> and <strong>access token</strong></li><li>the website sends to oidc endpoint <strong>(/userinfo)</strong> the access token for the user claims, roles, etc</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*ivE1O5d0I1qdgGAMJaEnHA.png" /></figure><p>After knowing the workflow we should circle back to some terminologies.</p><p><strong>ID token</strong> is a Json Web Token. These ID tokens consist of a header, payload, and signature. The header and signature are used to verify the authenticity of the token, while the payload contains the information about the user requested by your client. The ID token is the core extension that oidc makes to OAuth 2.0. ID tokens are issued by the authorization server and contain claims that carry information about the user.</p><p><em>worth to mention, id_token will not be returned unless you specify the scope to openid when contacting the oidc endpoint.</em></p><p><strong>Access Token </strong>is<strong> </strong>a unique token that tells the resource server that this user is authorized to access it with this limited scope.</p><p><strong>Authorization code </strong>is the authorization code is a temporary code that the client will exchange for an access token. The code itself is obtained from the authorization server where the user gets a chance to see what the information the client is requesting, and approve or deny the request</p><p><strong>Hands-on: apigee oauth 2.0 policy implementation</strong></p><p>First create a proxy and select which ever flow you like, for me i’ll go with proxy pre-flow and place <strong>OAuthV2</strong> policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/72/1*GF236tIzX9vDKp6pSh_K-g.png" /><figcaption>OAuthV2 Icon</figcaption></figure><p>Now to make this endpoint (flow) <strong>generates</strong> an access token you need to choose your preferred <strong>grant type </strong>for the sake of this tutorial will go with client_credentials grant type.</p><p>since we’re making this endpoint generates an access token we need to specify that on <strong>operation</strong> in the policy xml as shown below. you can also override the default value of the token life from <strong>ExpiresIn. </strong>If the scope was given in the xml then the token will be limited to this scope. Otherwise, it’ll be scoped to whatever your client application is subscribed to whatever product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*vSyKVxUR_tNE5a1gCmncRQ.png" /></figure><p>after building your policy all what you need now is to hit that endpoint with your client id and client secret (username and password).</p><p><strong>Resources</strong></p><ul><li><a href="https://blog.payara.fish/openid-connect-in-the-payara-platform-5.183">OpenID Connect in the Payara Platform 5.183</a></li><li><a href="https://auth0.com/docs/secure/tokens/access-tokens">Access Tokens</a></li><li><a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens">Microsoft identity platform ID tokens - Microsoft identity platform</a></li><li><a href="https://www.oauth.com/oauth2-servers/server-side-apps/authorization-code/">Authorization Code Grant - OAuth 2.0 Simplified</a></li><li><a href="https://www.onelogin.com/blog/openid-connect-explained-in-plain-english">OpenID Connect Explained in Plain English</a></li><li><a href="https://cloud.google.com/apigee/docs/api-platform/reference/policies/oauthv2-policy#generateaccesstoken">OAuthV2 policy | Apigee X | Google Cloud</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=758529e6f853" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/openid-connect-oauth-2-0-758529e6f853">OpenID Connect &amp; OAUTH 2.0</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kafka in a nutshell]]></title>
            <link>https://blog.devgenius.io/kafka-in-a-nutshell-8c597d5c9463?source=rss-8292967f9a55------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c597d5c9463</guid>
            <category><![CDATA[kafka-streams]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[ksql]]></category>
            <category><![CDATA[kafka-connect]]></category>
            <dc:creator><![CDATA[Lama Alosaimi]]></dc:creator>
            <pubDate>Wed, 12 Jan 2022 03:20:42 GMT</pubDate>
            <atom:updated>2022-01-18T08:23:58.566Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*Fldft8k-8Ff70tJs.jpg" /></figure><p>In this story I’ll explain what are <strong>Kafka</strong>, <strong>Kafka streams</strong> and <strong>Kafka connect </strong>and when to use each one.</p><p><strong>Kafka</strong></p><p>is a back-end application that provides a way to share streams of events between applications by sending/streaming messages to a topic on a Kafka broker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/0*bDjTJUzg4nsOxspy.png" /><figcaption>Kafka</figcaption></figure><p><strong>Kafka Streams</strong></p><p>is a client library for building applications and microservices. It makes it easier to transform or filter data from one Kafka topic and publish it to another Kafka topic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YH3c6medjNy_iTFp.png" /><figcaption>Kafka Streams</figcaption></figure><p><strong>Kafka Connect</strong></p><p>Kafka Connect is a tool for scalable and reliably streaming data between Apache Kafka® and other data systems. It makes it simple to quickly define connectors that move large data sets into and out of Kafka.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Wak5MbXGOqhBlRiv" /><figcaption>Kafka connect</figcaption></figure><p>Now if you have a use case where you want to publish and consume as is without any processing you may use the basic functionality of Kafka with producer and consumer. But if your use case requires some data transformation and complex processing you probably going to need streams, and you can create streams with KSQL in the confluent package. If your use case is something like syncing two databases or reading from a source and writing to a destination, then Kafka connect is the solution for you it supports many sources and destinations like Mysql, SqlServer, postgres, http, etc.</p><p><strong>Bonus $$ <br>Event-driven architecture with Kafka</strong></p><p>First, you need to know that EDA is a concept that can be done in various technologies but for the sake of Kafka we will go through it using Kafka. EDA is a way of dealing with the events that occur by a user and how your application interacts with these events. It is mainly used in real-time systems that respond to data changes and events as they occur in real-time.</p><p>An event can be anything generated by the user, It can be a mouse click, or pressing a key on the keyboard.</p><p>It is used when you want to manage different systems that respond to an event without having to write custom code for each consumer.</p><p><strong>Patterns of Event-Driven Architecture</strong></p><ol><li>SAGA</li></ol><p>In saga there are two types: choreography and orcherstration. The idea here is to put up sequence transactions that provide bigger and higher business purpose to manage data across microservices then we chain these transactions together. Each transaction updates the database and publishes an event to trigger the next transaction. If a transaction fails, saga will run compensation logic to go backwards and undo that effect or failure. Both of them do that but in the orcherstration there is an orcherstration service that manage the event publishing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*nYsX_QdxIIiw0thkaIAhjA.png" /><figcaption>saga choreography</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*3hDwijuS9I-DOYiNKnvDVg.png" /><figcaption>Saga orcherstration</figcaption></figure><p>2. Command and Query Responsibility Segregation (CQRS)</p><p>you divide the application into two segments, writing and reading. It may join pieces of data across various entities.</p><p>3. Event Sourcing</p><p>is an approach that handles data after a sequence of events. These event stores act as a history of records of the changes in the states of the data and notify the consumer to handle them.</p><p>4. Publish-Subscriber</p><p>The application will send message events to the consumers that are interested in updates. The sender will input a message to the input channel and pass it to the consumers. A message broker is responsible for copying each message from the publisher and sending it to all the subscribers.</p><p><strong>Spring Boot Application Examples</strong></p><p>here is a list of repos that utilized kafka in their business:</p><ul><li><a href="https://gitlab.com/lamoboos223/appointments-booking/-/tree/master">Files · master · Lama / Appointments Booking</a></li><li><a href="https://github.com/lamoboos223/Land-Fees">GitHub - lamoboos223/Land-Fees</a></li></ul><p><strong>References</strong></p><p><a href="https://www.upsolver.com/blog/apache-kafka-event-driven-architecture-streaming">Apache Kafka: Event-Driven Architecture &amp; Streaming | Upsolver</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FWnZ7IcaN_JA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DWnZ7IcaN_JA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FWnZ7IcaN_JA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a184f7ca395f4adc5c5867cb67db3eeb/href">https://medium.com/media/a184f7ca395f4adc5c5867cb67db3eeb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c597d5c9463" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/kafka-in-a-nutshell-8c597d5c9463">Kafka in a nutshell</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Boot Application With Multiple Data sources]]></title>
            <link>https://blog.devgenius.io/spring-boot-application-with-multiple-data-sources-9ccfbd6a0085?source=rss-8292967f9a55------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ccfbd6a0085</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Lama Alosaimi]]></dc:creator>
            <pubDate>Thu, 06 Jan 2022 21:45:29 GMT</pubDate>
            <atom:updated>2022-01-12T01:07:30.298Z</atom:updated>
            <content:encoded><![CDATA[<p>To make a spring boot application that can communicate with more than one database you need to define some configuration to let spring boot when to execute each source.</p><p>let’s agree first that your /<strong>models</strong> and /<strong>repositories</strong> and /<strong>controllers</strong> are already defined as you always do.</p><p>now let’s take a walk through the <strong>application.properties</strong> file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*11y4NOW9bBI5VUR8-jlr5A.png" /></figure><p>as you can see I have set the configuration for two databases. The first one is for <strong>Song</strong> and the second one for <strong>Lyrics</strong>. Note that the Song configuration prefixed with <strong>(spring.datasource.*)</strong> and Lyrics configuration prefixed with <strong>(spring.lyrics.datasource.*)</strong>, making the Song prefixed with (spring.song.datasource) would lead to error due to (spring.datasource.*) not provided so at least one of the databases should act like if it was the default database.</p><p>You should organize your models and repositories directories like this; in order to let the configuration code knows which model and repo to apply the data source to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*K4Vn4iiI7rkT0GTf5O1CSg.png" /></figure><p>now we’re done organizing the directories and submitting the database config in the application.properties we’re left with the spring boot configuration code for the data sources.</p><p>first, create a directory /<strong>config</strong> and create two java files for each datasource you have. mine will be <strong>SongDBConfig.java</strong> and <strong>LyricsDBConfig.java</strong></p><p>let’s start with SongDBConfig.java</p><pre>@Primary<br>@Bean(name=&quot;songProps&quot;)<br>@ConfigurationProperties(&quot;spring.datasource&quot;)<br>public DataSourceProperties dataSourceProperties() {<br>    return new DataSourceProperties();<br>}<br><br>@Primary<br>@Bean(name=&quot;datasource&quot;)<br>@ConfigurationProperties(prefix = &quot;spring.datasource&quot;)<br>public DataSource datasource(@Qualifier(&quot;songProps&quot;) DataSourceProperties properties){<br>    return properties.initializeDataSourceBuilder().build();<br>}<br><br>@Primary<br>@Bean(name=&quot;entityManagerFactory&quot;)<br>public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean<br>        (EntityManagerFactoryBuilder builder,<br>         @Qualifier(&quot;datasource&quot;) DataSource dataSource){<br>    return builder.dataSource(dataSource)<br>            .packages(&quot;com.example.multipledb.models.song&quot;)<br>            .persistenceUnit(&quot;Song&quot;).build();<br>}<br><br>@Primary<br>@Bean(name = &quot;transactionManager&quot;)<br>@ConfigurationProperties(&quot;spring.jpa&quot;)<br>public PlatformTransactionManager transactionManager(<br>        @Qualifier(&quot;entityManagerFactory&quot;) EntityManagerFactory entityManagerFactory) {<br>    return new JpaTransactionManager(entityManagerFactory);<br>}</pre><p>since Song db is our <strong>default</strong> data source it is a must to include “<strong>Primary</strong>” annotation which defines that this bean going to be registered more than one time but I want this version to be the primary one. So, in the other class LyricsDBConfig.java the bean <strong>won’t</strong> have the “Primary” annotation.</p><p>For the “ConfigurationProperties” annotation we used it to let spring boot know which configuration from application.properties should it use.</p><p>and let’s not forget to annotate our class with these annotations</p><pre>@Configuration<br>@EnableTransactionManagement<br>@EnableJpaRepositories(<br>        entityManagerFactoryRef = &quot;entityManagerFactory&quot;,<br>        transactionManagerRef = &quot;transactionManager&quot;,<br>        basePackages = { &quot;com.example.multipledb.repositories.song&quot; })<br>public class SongDBConfig {<br><br>    @Primary<br>    @Bean(name=&quot;songProps&quot;)<br>    @ConfigurationProperties(&quot;spring.datasource&quot;)<br>    public DataSourceProperties dataSourceProperties() {<br>        return new DataSourceProperties();<br>    }<br><br>    @Primary<br>    @Bean(name=&quot;datasource&quot;)<br>    @ConfigurationProperties(prefix = &quot;spring.datasource&quot;)<br>    public DataSource datasource(@Qualifier(&quot;songProps&quot;) DataSourceProperties properties){<br>        return properties.initializeDataSourceBuilder().build();<br>    }<br><br>    @Primary<br>    @Bean(name=&quot;entityManagerFactory&quot;)<br>    public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean<br>            (EntityManagerFactoryBuilder builder,<br>             @Qualifier(&quot;datasource&quot;) DataSource dataSource){<br>        return builder.dataSource(dataSource)<br>                .packages(&quot;com.example.multipledb.models.song&quot;)<br>                .persistenceUnit(&quot;Song&quot;).build();<br>    }<br><br>    @Primary<br>    @Bean(name = &quot;transactionManager&quot;)<br>    @ConfigurationProperties(&quot;spring.jpa&quot;)<br>    public PlatformTransactionManager transactionManager(<br>            @Qualifier(&quot;entityManagerFactory&quot;) EntityManagerFactory entityManagerFactory) {<br>        return new JpaTransactionManager(entityManagerFactory);<br>    }<br>}</pre><p>for the LyricsDBConfig.java it will be the same as SongDBConfig.java but we will prefix the entityManagerFactory and transactionManager with “<strong>lyrics</strong>” cause they’re already taken by the SongDBConfig.java</p><pre>@Configuration<br>@EnableTransactionManagement<br>@EnableJpaRepositories(<br>        entityManagerFactoryRef = &quot;lyricsEntityManagerFactory&quot;,<br>        transactionManagerRef = &quot;lyricsTransactionManager&quot;,<br>        basePackages = { &quot;com.example.multipledb.repositories.lyrics&quot; })<br>public class LyricsDBConfig {<br><br>    @Bean(name=&quot;lyricsProps&quot;)<br>    @ConfigurationProperties(&quot;spring.lyrics.datasource&quot;)<br>    public DataSourceProperties dataSourceProperties() {<br>        return new DataSourceProperties();<br>    }<br><br><br>    @Bean(name=&quot;lyricsDatasource&quot;)<br>    @ConfigurationProperties(prefix = &quot;spring.lyrics.datasource&quot;)<br>    public DataSource datasource(@Qualifier(&quot;lyricsProps&quot;) DataSourceProperties properties){<br>        return properties.initializeDataSourceBuilder().build();<br>    }<br><br><br>    @Bean(name=&quot;lyricsEntityManagerFactory&quot;)<br>    public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean<br>            (EntityManagerFactoryBuilder builder,<br>             @Qualifier(&quot;lyricsDatasource&quot;) DataSource dataSource){<br>        return builder.dataSource(dataSource)<br>                .packages(&quot;com.example.multipledb.models.lyrics&quot;)<br>                .persistenceUnit(&quot;Lyrics&quot;).build();<br>    }<br><br><br>    @Bean(name = &quot;lyricsTransactionManager&quot;)<br>    @ConfigurationProperties(&quot;spring.jpa&quot;)<br>    public PlatformTransactionManager transactionManager(<br>            @Qualifier(&quot;lyricsEntityManagerFactory&quot;) EntityManagerFactory entityManagerFactory) {<br>        return new JpaTransactionManager(entityManagerFactory);<br>    }<br>}</pre><p>now the controller will call each repo and by their turn will communicate the selected DB.</p><pre>@RestController<br>public class Controller {<br>    @Autowired<br>    LyricsRepo lyricsRepo;<br>    @Autowired<br>    SongRepo songRepo;<br><br>    @PostMapping<br>    public ResponseEntity add(@RequestBody request body){<br>        SongModel songModel = new SongModel();<br>        LyricsModel lyricsModel = new LyricsModel();<br>        songModel.setName(body.getSong());<br>        lyricsModel.setContent(body.getContent());<br><br>//        will insert in Song DB<br>        songRepo.save(songModel);<br>//        will insert in Lyrics DB<br>        lyricsRepo.save(lyricsModel);<br><br>        return ResponseEntity.<em>ok</em>(body);<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YF5CO0nluIyTc_yWXK0rkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*49hPMcRju_yygePIa_2i0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*Gj51qgAXP-jRr9zRvCkGyQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*VCLb5gIoS5Icshe4nk4oVA.png" /></figure><p>source code: <a href="https://gitlab.com/lamoboos223/spring-boot-multiple-datasource-song-project">https://gitlab.com/lamoboos223/spring-boot-multiple-datasource-song-project</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ccfbd6a0085" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/spring-boot-application-with-multiple-data-sources-9ccfbd6a0085">Spring Boot Application With Multiple Data sources</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>