<?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 Chaimae chakir on Medium]]></title>
        <description><![CDATA[Stories by Chaimae chakir on Medium]]></description>
        <link>https://medium.com/@chaimaechakir24?source=rss-a924d48afea0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*9U7218ThtjKGBxTDH0j81A.png</url>
            <title>Stories by Chaimae chakir on Medium</title>
            <link>https://medium.com/@chaimaechakir24?source=rss-a924d48afea0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:53:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chaimaechakir24/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[Boost Your Spring Boot Performance with Native Images and AOT Compilation]]></title>
            <link>https://medium.com/@chaimaechakir24/boost-your-spring-boot-performance-with-native-images-and-aot-compilation-d14010f46ba1?source=rss-a924d48afea0------2</link>
            <guid isPermaLink="false">https://medium.com/p/d14010f46ba1</guid>
            <dc:creator><![CDATA[Chaimae chakir]]></dc:creator>
            <pubDate>Mon, 14 Jul 2025 12:34:43 GMT</pubDate>
            <atom:updated>2025-08-16T21:35:56.317Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve ever wished your Spring Boot applications would start faster and consume less memory, it’s time to explore <strong>Ahead-of-Time (AOT) compilation</strong> and <strong>native images</strong>. In this article, I’ll explain how these technologies work and how you can apply them to boost the performance of your Spring Boot projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yakgg-Vt8kFsHMIYrg2XYQ.jpeg" /></figure><h3>What is AOT Compilation?</h3><p><strong>AOT</strong> stands for <strong>Ahead-of-Time Compilation</strong>. In traditional Java applications, most code is compiled at runtime using <strong>Just-in-Time (JIT) compilation</strong>. With AOT compilation, part of the work is done before the application starts. Spring processes bean definitions and configuration ahead of time, which helps reduce startup time and lower memory usage in production. AOT also generates runtime hints for reflection, resources, serialization, and proxies. Additionally, it is required for building native executables with <strong>GraalVM</strong>.</p><h3>Why Compile to Native?</h3><p>Native images compiled with <strong>GraalVM</strong> offer several key benefits:</p><ul><li>🚀 <strong>Instant Startup</strong> — Applications launch in milliseconds instead of seconds</li><li>⏱️ <strong>No Warmup Required</strong> — Peak performance from the first request</li><li>💾 <strong>Lower Memory Usage</strong> — No JIT compiler overhead</li><li>🛡️ <strong>Reduced Attack Surface</strong> — Reflection must be explicitly declared</li><li>📦 <strong>Smaller Packaging</strong> — Suitable for lightweight containers and serverless</li><li>💰 <strong>Lower Infrastructure Costs</strong> — Optimized resource consumption</li></ul><h3>Hands-On Demo</h3><h3>Set Up a Spring Boot Project with Native Support</h3><p>Start by creating a simple Spring Boot project, for example using <a href="https://start.spring.io/">Spring Initializr</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6LzFfEyqdS4Okn0Bi1w3Q.png" /></figure><p>Add a basic REST controller like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*qWsmWGH1DC5qrR151Il2hQ.png" /></figure><h3>Install GraalVM</h3><p>Download and install <strong>GraalVM</strong> along with the <strong>Native Image</strong> tool from the <a href="https://www.graalvm.org/">official GraalVM website</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eDSCbKnMvJ0om_GhOop5cg.png" /></figure><p>Build as a Regular JAR</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*No7DGd8xEJ9P810jKKZLeQ.png" /></figure><p>Run as a Regular JAR</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W984gv0Tt-TxR7vW1eSgmw.png" /></figure><p>Startup time: approximately <strong>1.8 seconds</strong></p><p>Build as a Native Image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F_sByrv8ICmVDePTu_j0hg.png" /></figure><p>Run as a Native Image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WiFrgLEMfLFSDJHdWGvcGA.png" /></figure><p>Startup time: approximately <strong>0.33 seconds</strong></p><p>With <strong>Spring Boot AOT</strong> and <strong>GraalVM Native Image</strong>, you can significantly reduce startup time and memory usage. These technologies are especially useful for microservices, serverless applications, and cloud-native deployments. If you’re looking to optimize your Spring Boot applications for performance and cost, experimenting with AOT and native images is a great place to start.</p><p>References:</p><p><a href="https://docs.spring.io/spring-boot/reference/packaging/native-image/index.html">https://docs.spring.io/spring-boot/reference/packaging/native-image/index.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d14010f46ba1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java 21 Virtual Threads: What You Need to Know]]></title>
            <link>https://medium.com/@chaimaechakir24/java-21-virtual-threads-what-you-need-to-know-a9d34962d654?source=rss-a924d48afea0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9d34962d654</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[multithreading]]></category>
            <category><![CDATA[virtual-threads]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[java-21-features]]></category>
            <dc:creator><![CDATA[Chaimae chakir]]></dc:creator>
            <pubDate>Mon, 07 Jul 2025 16:02:08 GMT</pubDate>
            <atom:updated>2025-07-07T20:45:51.698Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*JRKvhKch8O5wOtQg.png" /></figure><p>Let’s be honest — learning about threads and multithreading in Java can be confusing. Terms like<strong> “context switching”</strong> and <strong>“concurrent programming”</strong> might sound intimidating, especially for beginners.</p><p>Fortunately, Java 21 introduces <strong>Virtual Threads</strong>, a new feature that simplifies running many tasks concurrently in a more efficient and lightweight way.</p><p>In this article, I’ll walk you through this concept step by step using simple language and relatable examples.</p><h3>1. How Does a Computer Run Many Things Together?</h3><p>Even if your computer has only one CPU, you can still open multiple applications like Chrome, Excel, or a music player at the same time.</p><p>This happens through a technique called <strong>time slicing</strong> — the CPU gives each task a tiny slice of time, rapidly switching between them. It’s so fast that it feels like everything runs at once.</p><p>If your computer has <strong>multiple cores</strong>, each can truly run a different task in parallel, while also using time slicing internally. That’s how multitasking works.</p><h3>2. What Are Threads in Java?</h3><p>Sometimes, a single program needs to perform multiple tasks at once. For example:</p><ul><li>Showing a progress bar while downloading a file</li><li>Playing music while loading an image</li><li>Handling 500 users on a website simultaneously</li></ul><p>Java solves this using <strong>threads</strong> — lightweight workers that execute code independently.</p><p>Example (like in Chrome):</p><ul><li>One thread downloads a file</li><li>Another renders a webpage</li><li>Another plays a YouTube video</li></ul><p>This is called <strong>multithreading</strong>.</p><h3>3. Old Method: Platform Threads</h3><p>Traditional threads in Java are known as <strong>platform threads</strong>. When your code creates a thread, the JVM asks the operating system (OS) to manage it.</p><p>The OS handles:</p><ul><li>Memory for the thread (usually ~1 MB per thread)</li><li>Scheduling and CPU usage</li></ul><p>Problems with this approach:</p><ul><li>Creating thousands of threads consumes huge memory (10,000 threads ≈ 10 GB)</li><li>Context switching between threads is expensive</li><li>Even idle threads consume resources</li></ul><p>In short: platform threads are <strong>heavy</strong> and not ideal for highly concurrent systems.</p><h3>4. The Problem with Blocking</h3><p>Let us take an example. You have a Java web application that handles 10,000 requests. Each request does the following:</p><ul><li>Calls a database (takes 200ms)</li><li>Waits for a payment API</li><li>Sends the response to the user</li></ul><p>While waiting for the database or API, the thread is doing nothing useful. But still, it is using memory and CPU resources. This is a waste.</p><p>Most of these tasks are not heavy. They are just waiting for a reply. So why should we use heavy platform threads to simply wait?</p><h3>5. What Are Virtual Threads?</h3><p>This is where <strong>Virtual Threads</strong> come in. This is a new feature in Java under <strong>Project Loom</strong>.</p><p>Virtual threads are lightweight and created by the JVM. They are not managed by the OS. You can create thousands or even millions of virtual threads without worrying about memory.</p><p>How do they work?</p><ul><li>You start a virtual thread to handle a task</li><li>If it needs to wait (for DB or API), the JVM <strong>parks</strong> it</li><li>The real OS thread is freed and can be used for other work</li><li>When the response comes, the JVM resumes the virtual thread</li></ul><p>This way, virtual threads do not block OS threads. They use less memory and CPU.</p><h3>6. Do I Need to Change My Code?</h3><p>Good news. You do not have to change your entire code. You can write normal blocking code. No need to learn complex async or reactive programming.</p><p>To create a virtual thread, just do this:</p><blockquote>Thread.startVirtualThread(() -&gt; {</blockquote><blockquote>// Your logic here</blockquote><blockquote>});</blockquote><p>That’s it. The rest is handled by the JVM.</p><h3>7. Benefits of Virtual Threads</h3><p>Here are the main advantages:</p><ul><li>You can create 100,000+ threads easily</li><li>You write simple code (just like before)</li><li>Less memory is used (no 1 MB per thread)</li><li>Less CPU is wasted on switching or waiting</li></ul><p>Your program stays clean and readable, but still handles a lot of work.</p><h3>8. When to Use Virtual Threads</h3><p>Virtual threads are perfect for <strong>I/O-heavy</strong> tasks like:</p><ul><li>Web servers</li><li>Microservices</li><li>Apps that call many APIs or databases</li></ul><p>If your program is doing <strong>CPU-heavy</strong> work (like image processing, video rendering, data analysis), then virtual threads may not give much benefit.</p><p>But for most modern backend applications, they are a great choice.</p><h3>Final Thoughts</h3><p>Virtual threads are a big improvement in Java. They make it easy to write simple and clean code that can handle thousands of tasks.</p><p>You no longer need to worry about complex thread management or async code.</p><p>So if you are building a web app, backend service, or anything that handles many users or requests, you should start using virtual threads.</p><h3>📘 Optional Sources :</h3><p>Java 21 release notes: <a href="https://www.oracle.com/java/technologies/javase/21-relnote-issues.html">https://www.oracle.com/java/technologies/javase/21-relnote-issues.html</a></p><p>Official Java Virtual Threads page: <a href="https://openjdk.org/jeps/444">https://openjdk.org/jeps/444</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9d34962d654" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why You Should Never Store JWTs in localStorage: A Simple Guide to Safer Authentication]]></title>
            <link>https://medium.com/@chaimaechakir24/why-you-should-never-store-jwts-in-localstorage-a-simple-guide-to-safer-authentication-63d1651092a6?source=rss-a924d48afea0------2</link>
            <guid isPermaLink="false">https://medium.com/p/63d1651092a6</guid>
            <category><![CDATA[jwt-authentication]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[jwt]]></category>
            <dc:creator><![CDATA[Chaimae chakir]]></dc:creator>
            <pubDate>Sun, 29 Jun 2025 15:06:37 GMT</pubDate>
            <atom:updated>2025-06-29T15:06:37.138Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*VJO2TOFOT9E_rsjEMkE9Zg.png" /></figure><p>Many web apps today use <strong>JWTs (JSON Web Tokens)</strong> for login and authentication. A common way to store these tokens is in <strong>localStorage</strong> or <strong>sessionStorage</strong> because it’s quick and easy.</p><p>But here’s the problem:<br> 🛑 <strong>This method is not safe.</strong></p><p>If you’re storing JWTs this way, your app could be vulnerable to serious attacks. Let me explain why and show you a better, more secure alternative.</p><p><strong>🚨 The Risks of Storing Tokens in localStorage/sessionStorage</strong></p><p><strong>1. XSS Attacks (Cross-Site Scripting)</strong></p><p>Anything stored in localStorage or sessionStorage is accessible via JavaScript. That means if a hacker injects a malicious script into your page (via a third-party library or browser extension), they can steal your token.</p><p>Unlike httpOnly cookies, which JavaScript can’t read, localStorage is wide open.</p><p><strong>2. Tokens Don’t Expire Automatically</strong></p><p>Cookies can be set to expire after a certain time. But localStorage data stays there forever unless you manually delete it. If a hacker steals your JWT, they can use it until you change your backend logic or rotate keys.</p><p><strong>3. Switching to Cookies? Watch Out for CSRF</strong></p><p>Some devs switch to cookies for better security but that introduces <strong>CSRF (Cross-Site Request Forgery)</strong> risks unless you:</p><ul><li>Set SameSite=Strict</li><li>Use CSRF tokens on state-changing requests</li></ul><p><strong>✅ A Safer Alternative: BFF (Backend-for-Frontend) + Redis</strong></p><p>To avoid all these problems, many teams now use a pattern called <strong>BFF (Backend-for-Frontend)</strong> along with <strong>server-side token storage</strong> (like <strong>Redis</strong>).</p><p>Here’s how it works:</p><p><strong>🔐 The Frontend Never Sees the JWT</strong></p><ul><li>The <strong>backend handles authentication</strong>, stores JWTs in Redis, and sends the frontend only an <strong>httpOnly cookie</strong> with a session ID.</li><li>This cookie is not accessible to JavaScript so no chance of XSS.</li><li>All token management happens on the server.</li></ul><p><strong>🔁 How the Flow Works</strong></p><ul><li><strong>Login:</strong> User submits login form → BFF checks credentials → JWTs are created and stored in Redis → frontend receives an httpOnly cookie.</li><li><strong>API Request:</strong> Frontend sends the cookie → BFF looks up tokens in Redis → forwards request to backend API.</li><li><strong>Refresh Token:</strong> When the JWT expires, the BFF uses the <strong>refresh token</strong> (stored securely in Redis) to get a new one automatically.</li><li><strong>Logout:</strong> BFF deletes the session from Redis → token is instantly invalidated.</li></ul><p><strong>🧠 Why Redis?</strong></p><ul><li><strong>Speed:</strong> Redis is extremely fast (sub-millisecond), perfect for token lookups.</li><li><strong>Expiry:</strong> Redis supports auto-expiry (TTL), so you don’t need to manually delete old tokens.</li><li><strong>Revocability:</strong> You can invalidate tokens anytime by just deleting them from Redis, something you <strong>can’t</strong> do with normal stateless JWTs.</li></ul><p><strong>✅ Key Benefits</strong></p><ul><li><strong>No XSS Risk:</strong> JWTs never touch the browser. JavaScript can’t steal what it can’t see.</li><li><strong>Better Session Control:</strong> Use short-lived access tokens (e.g., 15 mins) and long-lived refresh tokens (e.g., 7 days) for better balance between security and user experience.</li><li><strong>Scalable:</strong> Redis can handle millions of sessions. Perfect for large-scale apps.</li></ul><p><strong>🧰 When Should You Use This?</strong></p><p>This setup is great for:</p><ul><li>Single Page Apps (SPAs) built with <strong>React</strong>, <strong>Vue</strong>, or <strong>Angular</strong></li><li>Mobile apps where token theft is a risk</li><li>Microservices architectures where token validation needs to be centralized</li></ul><p><strong>🛠️ Final Thoughts</strong></p><p>Yes, localStorage is convenient — but it’s <strong>not secure</strong> for storing authentication tokens.</p><p>🔒 <strong>The BFF + Redis approach gives you:</strong></p><ul><li>Strong security (no XSS or CSRF)</li><li>Smooth UX (silent refreshes, instant logout)</li><li>Flexibility and performance at scale</li></ul><p><strong>📝 What to Do Next</strong></p><ul><li>✅ Use httpOnly + Secure + SameSite cookies</li><li>✅ Store tokens in Redis with persistence (RDB/AOF)</li><li>✅ Consider <strong>token binding</strong> (e.g., tie tokens to IP or device ID)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63d1651092a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>