<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sumit</title>
    <description>The latest articles on DEV Community by Sumit (@tech_sam).</description>
    <link>https://dev.to/tech_sam</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F112013%2F9c503162-1d43-441f-861e-021f7696774b.png</url>
      <title>DEV Community: Sumit</title>
      <link>https://dev.to/tech_sam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tech_sam"/>
    <language>en</language>
    <item>
      <title>Elegance Was Never Dead: The Return of Perfectionism</title>
      <dc:creator>Sumit</dc:creator>
      <pubDate>Tue, 22 Apr 2025 18:32:49 +0000</pubDate>
      <link>https://dev.to/tech_sam/elegance-was-never-dead-the-return-of-perfectionism-14ca</link>
      <guid>https://dev.to/tech_sam/elegance-was-never-dead-the-return-of-perfectionism-14ca</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;“Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away.” — Antoine de Saint-Exupéry&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This isn’t a technical guide, or a tutorial on prompts, or a love letter to the latest framework. It’s something quieter. A reflection on a mindset. On how, as technology accelerates especially with AI we’re beginning to rediscover old ideas under new light.&lt;/p&gt;

&lt;p&gt;There was a time when writing code felt like sculpting. Every line held intention. Every decision carried the weight of future maintainability, readability, and pride. Maybe you’ve known someone who’d refactor a function not because it was broken, but because it could be clearer. Maybe you’ve been that someone. And while others rushed ahead, you stayed behind naming things well, splitting methods with care, shaping the invisible structure with the same reverence an architect might shape a quiet, sturdy home.&lt;/p&gt;

&lt;p&gt;That wasn’t wasted effort. That was a kind of poetry. We didn’t call it over-engineering we called it love for the craft.&lt;/p&gt;

&lt;p&gt;But something has shifted. Not for the worse, not for the better just… algorithmically different. Today, with AI tools like GPT, Claude, Copilot, Cursor, Amazon CodeWhisperer, Tabnine, and the ever-mysterious "vibe coding" mood board that is Twitter dev threads, more and more of our code is being drafted by something that doesn’t sleep, doesn’t snack, and definitely doesn’t understand context.&lt;/p&gt;

&lt;p&gt;We’re no longer just authors we’re editors, reviewers, damage control. We’re the second pair of eyes that needs to see what the first pair a well-meaning, overconfident autocomplete engine might have hallucinated into existence.&lt;/p&gt;

&lt;p&gt;Perfectionism, once feared as a productivity sinkhole, is quietly reclaiming its space. But not as pixel-pushing or infinite refactoring. Now, it shows up as thoughtful inspection. As a pause. As a second thought. It’s less about elegance, more about integrity.&lt;/p&gt;

&lt;p&gt;Aristotle spoke of the Golden Mean the virtue that lives between two extremes. For many years, we believed the middle path in software was shipping fast, keeping things simple, and avoiding the rabbit hole of over design. But maybe that balance is shifting. Maybe, in the age of AI-assisted development, a little more scrutiny, a little more intention, is what brings us back to the center.&lt;/p&gt;

&lt;p&gt;In this new world, being a perfectionist doesn’t mean resisting change or clinging to old ways. It means adapting without forgetting why we cared about quality in the first place. It means knowing that while AI might take the wheel, we’re still the ones reading the road.&lt;/p&gt;

&lt;h2&gt;
  
  
  Between Autopilot and Paranoia: The Mindful Path of Perfectionism
&lt;/h2&gt;

&lt;p&gt;In practice, balance today looks like mindful development. The kind that asks you to slow down, even when the machine speeds up. It’s less about resisting AI and more about learning how to work alongside it without losing your own sense of judgment.&lt;/p&gt;

&lt;p&gt;It’s a bit like the mindset from Zen Buddhism: be present, be deliberate. When the AI spits out a chunk of code, I don’t react with blind trust (too lax) or with immediate rejection (too rigid). I try to sit with it. Ask questions. Is it readable? Is it safe? Does it actually solve the right problem?&lt;/p&gt;

&lt;p&gt;There’s a Zen saying: “Before enlightenment, chop wood, carry water. After enlightenment, chop wood, carry water.” For us, it’s: Before AI, write code, debug code. After AI… write code, debug code. The work hasn’t disappeared it’s just shapeshifted. The same rituals remain. I still have to carry water, so to speak. Just now, I carry it in a review comment, a test case, a rewritten function.&lt;/p&gt;

&lt;p&gt;If Marcus Aurelius were a tech lead, he might remind us to “love the framework of fate” not to curse the tools for what they get wrong, but to treat their flaws as part of the job. We don’t get to choose the wave, but we do get to learn how to surf it.&lt;/p&gt;

&lt;p&gt;Finding that balance isn’t formulaic. It’s an instinct built over time. It’s noticing when the AI starts hallucinating confidence into broken logic. It’s choosing to simplify a generated solution instead of praising its complexity. And sometimes, it’s about trusting your own discomfort when something looks right but doesn’t feel right.&lt;/p&gt;

&lt;p&gt;The Golden Mean isn’t static. It shifts with context. And in 2025, it just might live somewhere between accepting every AI suggestion and rewriting everything by hand.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Return of Thoughtful Perfectionism
&lt;/h2&gt;

&lt;p&gt;I find it ironic and exciting that a thoughtful form of perfectionism is making a comeback in software engineering. No, we’re not back to obsessing over whether to name a variable &lt;code&gt;tempData&lt;/code&gt; or &lt;code&gt;intermediateResult&lt;/code&gt; for hours, nor are we adding pointless abstractions for theoretical use cases. &lt;br&gt;
This new perfectionism is different: it’s human-guided, principle-driven, and focused on safety and clarity. It’s a recognition that in an age where code can be machine-generated in an instant, the real value a seasoned developer adds is thoughtfulness the kind of careful thinking that machines can’t (yet) do.&lt;/p&gt;

&lt;p&gt;In practical terms, this means we care about things like correctness, security, and transparency of code more than ever. We double-check that the AI’s code doesn’t have hidden pitfalls. We enforce coding standards so that the next human (or next AI) reading the code can understand it without psychic powers. We pay attention to performance implications and edge cases that an auto-generated solution might miss. We treat code not as an ephemeral throwaway just because it was easy come, easy go, but as an artifact that will live on and needs to be trustworthy.&lt;/p&gt;

&lt;p&gt;Ultimately, this is leading us to a more balanced engineering culture. Speed and efficiency from AI plus careful human oversight can coexist. We are learning to harness the brute-force productivity of our silicon sidekicks while applying the nuanced judgment that comes from experience and yes, from our human sense of craftsmanship. The goal is no longer perfection for perfection’s sake (it never really should have been), but a kind of perfectionism with purpose: making the software better in ways that truly matter more robust, more secure, more understandable. It’s almost like we’re channeling that old perfectionist energy, but instead of pouring it into gold-plating the design, we’re pouring it into fortifying the code’s integrity.&lt;/p&gt;

&lt;p&gt;So, is perfectionism in software engineering dead now that AI is writing code? Far from it. It’s evolving. We’ve gone from lovingly hand-carving every solution, to sometimes accepting quick and dirty code, and now to lovingly cleaning up quick code. In this journey, we may have rediscovered why we cared about “perfect” code in the first place. Not to satisfy some OCD impulse or to impress others with cleverness, but to ensure our software works well and can be maintained by real people. In the end, the “perfect code” was never about having zero flaws that’s impossible but about striving for excellence where it counts.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The quest for quality has come full circle. The tools and techniques have changed, but the heart of the matter is the same.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;this is the beginning of a new era not where machines replace our standards, but where they challenge us to uphold them with even greater clarity.&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

</description>
      <category>perfectionism</category>
      <category>programming</category>
      <category>ai</category>
      <category>codingphilosophy</category>
    </item>
    <item>
      <title>Squeezing the Most Out of Every Byte: Go's Memory Packing Secrets Unpacked!</title>
      <dc:creator>Sumit</dc:creator>
      <pubDate>Sun, 14 Apr 2024 10:34:24 +0000</pubDate>
      <link>https://dev.to/tech_sam/squeezing-the-most-out-of-every-byte-gos-memory-packing-secrets-unpacked-1na4</link>
      <guid>https://dev.to/tech_sam/squeezing-the-most-out-of-every-byte-gos-memory-packing-secrets-unpacked-1na4</guid>
      <description>&lt;p&gt;Go is renowned for its straightforward design, favored for cloud-native applications. It boasts unique flair and special features, often tipping the scales toward favoritism thanks to its &lt;strong&gt;engineering marvels under the hood&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Discuss Padding in Structs?
&lt;/h3&gt;

&lt;p&gt;In the fast-paced world of software development, where generative AI can churn out articles in minutes, it's crucial to dive deeper into topics that AI might gloss over. This blog aims to shed light on a seemingly niche yet critical aspect of Go—&lt;strong&gt;struct padding&lt;/strong&gt;. This clever feature optimizes memory usage so efficiently that it might just tip the scales for Java developers considering a switch. It’s like Go is saying, “Come for the simplicity, stay for the memory management!”&lt;/p&gt;

&lt;p&gt;In Go, a struct is a fundamental building block for data organization. A struct is a user-defined type that groups elements of various data types under a single name, similar to a record in a database. This makes it incredibly useful for data transfer and managing related data together, much like a custom toolkit where each tool has a specific role.&lt;/p&gt;

&lt;p&gt;Let's look at a more contemporary and relevant example than the classic Car struct—consider a User Authentication Module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type UserSession struct {
    userID    uint64  // 8 bytes
    timestamp uint64  // 8 bytes
    isActive  bool    // 1 byte
    isLoggedIn bool   // 1 byte
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Struct Padding Explained
&lt;/h3&gt;

&lt;p&gt;Now, let's delve into struct padding. Struct padding in Go ensures that the fields within structs are aligned according to the CPU's word size to facilitate faster access. But what does this mean? Let’s break it down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Word Size&lt;/strong&gt;: This refers to the number of bytes the CPU can process at one time. On a 64-bit system, the word size is 8 bytes, meaning the CPU can handle 8 bytes of data in a single operation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Alignment&lt;/strong&gt;: For the CPU to process data most efficiently, the data needs to be aligned in memory according to the word size. This means that data types should ideally begin at memory addresses that are multiples of their size, up to the word size.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, on a 64-bit system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A 1-byte bool field should be aligned to a 1-byte boundary (any address).&lt;/li&gt;
&lt;li&gt;A 4-byte int32 field should be aligned to a 4-byte boundary (address divisible by 4).&lt;/li&gt;
&lt;li&gt;An 8-byte uint64 field should be aligned to an 8-byte boundary (address divisible by 8).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When struct fields are not naturally aligned with these boundaries, the Go compiler will automatically insert "padding" — extra space — between fields. This padding ensures that each field starts at an address that aligns with its size, optimizing memory access during runtime.&lt;/p&gt;

&lt;p&gt;For instance, consider an imaginary application &lt;em&gt;High-Performance User Session Manager&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type UserSession struct {
    isActive  bool    // 1 byte
    // 7 bytes of padding here to align the next field
    userID    uint64  // 8 bytes
    isAdmin   bool    // 1 byte
    // 7 bytes of padding here to align the next field
    timestamp uint64  // 8 bytes
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In this example, the isActive and isAdmin fields are 1 byte each, but they are followed by 8-byte uint64 fields (userID and timestamp). &lt;br&gt;
To ensure that the userID and timestamp fields are properly aligned, the Go compiler adds 7 bytes of padding after the isActive and isAdmin fields, respectively.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This padding ensures that the CPU can access the 8-byte fields efficiently, as they are now aligned to 8-byte boundaries in memory. While the padding may seem like a waste of memory, it's a trade-off that the Go compiler makes to optimize the performance of memory access.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Initial Analysis with Unsafe Package
&lt;/h3&gt;

&lt;p&gt;Using the unsafe package, we can inspect the size and alignment of this struct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
    "unsafe"
)

func main() {
    var s UserSession
    fmt.Println("Size of Session struct:", unsafe.Sizeof(s))
    fmt.Println("Alignment of Session struct:", unsafe.Alignof(s))
    fmt.Println("Offset of isActive:", unsafe.Offsetof(s.isActive))
    fmt.Println("Offset of userID:", unsafe.Offsetof(s.userID))
    fmt.Println("Offset of isAdmin:", unsafe.Offsetof(s.isAdmin))
    fmt.Println("Offset of timestamp:", unsafe.Offsetof(s.timestamp))

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This script will output the size of the Session struct as well as the offsets of each field. Initially, we might find that the struct uses more memory than necessary due to padding added after the bool fields to align the struct to 8 bytes (since it's the largest alignment requirement in the struct).&lt;/p&gt;

&lt;p&gt;Here's what each function call in the provided code snippet does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;unsafe.Sizeof(s)&lt;/code&gt;: This function returns the total size in bytes of the struct s, including any padding added by Go to align the fields in memory.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;unsafe.Alignof(s)&lt;/code&gt;: This function returns the alignment of the struct s. Alignment dictates how the start of the struct should be positioned in memory. Typically, this is the largest alignment of any field within the struct, which helps ensure that all fields meet their alignment requirements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;unsafe.Offsetof(s.userID)&lt;/code&gt;: This function returns the byte offset of the field userID within the struct s. The offset is the distance from the start of the struct to the start of the field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;unsafe.Offsetof(s.timestamp)&lt;/code&gt;: Similar to the offset for userID, this gives the distance from the start of the struct to the timestamp field.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These functions are particularly useful for understanding the memory layout of your structs, which can help in optimizing performance, especially in systems programming, or when interfacing with hardware or operating system APIs where precise control over memory layout is necessary.&lt;/p&gt;

&lt;h3&gt;
  
  
  Go Tooling for Struct Layout Analysis
&lt;/h3&gt;

&lt;p&gt;While the &lt;code&gt;unsafe&lt;/code&gt; package provides a low-level way to inspect struct layout, Go offers a more convenient tool specifically designed for this purpose: &lt;code&gt;go tool structlayout&lt;/code&gt;. This tool can be used to visualize the memory layout of your structs, including field offsets and padding bytes. Here's an example of using &lt;code&gt;go tool structlayout&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go tool structlayout -layout UserSession
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will print a detailed breakdown of the UserSession struct layout, making it easier to identify any padding introduced by the compiler.&lt;/p&gt;

&lt;h3&gt;
  
  
  Optimizing the Struct Layout
&lt;/h3&gt;

&lt;p&gt;To minimize memory usage, we can reorder the fields to place all 8-byte fields first, followed by smaller fields, reducing the need for padding:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type OptimizedSession struct {
    userID    uint64  // 8 bytes
    timestamp uint64  // 8 bytes
    isActive  bool    // 1 byte
    isAdmin   bool    // 1 byte
    // Padding of 6 bytes here to align to 8 bytes
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Alternative Optimization: Using Pointers for Small Fields
&lt;/h3&gt;

&lt;p&gt;In some cases, depending on how these fields are accessed, an alternative optimization technique might be to use pointers for the smaller fields (isActive and isAdmin) if they are frequently accessed together with the larger fields. This can help reduce the overall memory footprint, especially when dealing with a large number of structs. However, it's important to consider the trade-offs between memory usage and code complexity when making this decision.&lt;/p&gt;

&lt;h3&gt;
  
  
  Profiling Memory Impact
&lt;/h3&gt;

&lt;p&gt;We can compare the memory usage before and after the optimization using a benchmark test in Go. This test will create a large number of session structs and measure the total memory used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "testing"
    "unsafe"
)

func BenchmarkOriginalSession(b *testing.B) {
    for i := 0; i &amp;lt; b.N; i++ {
        _ = UserSession{
            isActive:  true,
            userID:    123456789012345,
            isAdmin:   false,
            timestamp: 1609459200,
        }
    }
}

func BenchmarkOptimizedSession(b *testing.B) {
    for i := 0; i &amp;lt; b.N; i++ {
        _ = OptimizedSession{
            userID:    123456789012345,
            timestamp: 1609459200,
            isActive:  true,
            isAdmin:   false,
        }
    }
}

func main() {
    var originalSize = unsafe.Sizeof(UserSession{})
    var optimizedSize = unsafe.Sizeof(OptimizedSession{})
    println("Original Session size:", originalSize)
    println("Optimized Session size:", optimizedSize)
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This benchmarking will help demonstrate the memory savings achieved by simply reordering struct fields. &lt;/p&gt;

&lt;p&gt;The memory savings from switching from the non-optimized to the optimized layout are:&lt;br&gt;
&lt;code&gt;32 bytes (non-optimized) - 24 bytes (optimized) = 8 bytes saved&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Although each individual struct might only save a few bytes, in a high-load scenario where millions of these structs could be in memory at once, the overall memory savings can be significant.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Critical Note on Optimization
&lt;/h3&gt;

&lt;p&gt;Although the Go compiler is quite adept at handling most memory optimization tasks, many developers, myself included, often strive for perfection in optimizing every byte of memory usage. This can be seen as a kind of compulsion to make everything as efficient as possible—a common trait among developers.&lt;/p&gt;

&lt;p&gt;However, it's important to note that such detailed optimization isn't always necessary, especially in environments where the cost of hardware or computing resources (like your AWS bill) isn't a constraint. In these cases, the default optimizations performed by the Go compiler should be more than sufficient. Over-optimizing can lead to more complex and harder-to-maintain code without significant benefits in many practical applications.&lt;/p&gt;

&lt;p&gt;So, while it's great to know how to squeeze every byte for performance-critical applications, remember that sometimes throwing more hardware at a problem is a perfectly valid solution too!&lt;/p&gt;

&lt;h3&gt;
  
  
  Trade-offs of Struct Padding
&lt;/h3&gt;

&lt;p&gt;It's important to acknowledge that while struct padding improves performance by aligning memory access, it can also affect cache locality in some cases. Cache locality refers to the principle that data likely to be accessed together should be stored close together in memory to minimize the time it takes to retrieve it. When padding increases the distance between frequently accessed fields, it can lead to more cache misses, potentially negating some of the performance benefits of alignment.&lt;/p&gt;

&lt;p&gt;This trade-off between alignment and cache locality is a more advanced topic, but it's worth keeping in mind when considering struct padding optimizations. In most cases, the performance benefits of alignment outweigh the potential drawbacks for cache locality. However, for highly performance-critical scenarios, it might be necessary to delve deeper into cache behavior and profiling to make informed decisions.&lt;/p&gt;

&lt;p&gt;I hope this comprehensive explanation clarifies struct padding in Go and provides valuable insights for optimizing your data structures!&lt;/p&gt;

</description>
      <category>go</category>
      <category>structs</category>
      <category>memeorymanagement</category>
    </item>
    <item>
      <title>API security Part-1</title>
      <dc:creator>Sumit</dc:creator>
      <pubDate>Sat, 27 Feb 2021 15:37:50 +0000</pubDate>
      <link>https://dev.to/tech_sam/api-security-part-1-2h5m</link>
      <guid>https://dev.to/tech_sam/api-security-part-1-2h5m</guid>
      <description>&lt;p&gt;Today, most modern web applications are running on browsers, and most of you know how it works HTML, CSS, javascript, etc.&lt;/p&gt;

&lt;p&gt;Let's consider a simple web application that shows some reviews on a user's post a simple, &lt;a href="https://stackify.com/what-are-crud-operations/"&gt;crud&lt;/a&gt; app.&lt;/p&gt;

&lt;p&gt;Once the application loaded on a browser first time, nothing excited because there is no data. The application will load some data from a server with some API, performing operations and the security pitfalls that you might encounter at this level, and that's the point of this blog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6z02sybkcw81dukem3fy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6z02sybkcw81dukem3fy.jpg" alt="api-call" width="800" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you know, it is not just about web apps, and it refers to mobile apps, &lt;a href="https://www.electronjs.org/"&gt;electron apps&lt;/a&gt;, etc. All these types of applications use APIs. &lt;/p&gt;

&lt;p&gt;Every day, we hear about APIs being exposed and having their security compromised—not an uncommon story. Therefore, it's essential to have best practices in place to be successful.&lt;/p&gt;

&lt;p&gt;Today everybody has to consider API security whether you are a user of an API or provider. In this blog, we will look at some pitfalls and some pointers where to look at your application and where to look at when using other's APIs to improve the security of the application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://owasp.org/www-project-top-ten/"&gt;OWASP Top Ten&lt;/a&gt; inspires this blog, A awareness document related to the most dangerous web security vulnerabilities published by the OWASP organization. Every developer should be aware of this document.&lt;/p&gt;

&lt;p&gt;We will specifically be focusing on OWASP 2017 A10 – Underprotected APIs section.&lt;/p&gt;

&lt;p&gt;First, let's discuss some incidents that cause too much damage to particular companies' reputations and businesses because of neglecting API security.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;In 2017, &lt;a href="https://www.bbc.com/news/technology-42030109"&gt;Germany banned children's smartwatches&lt;/a&gt;, which means the device meant to be secure for children providing the location to their parents has some significant security flaws.&lt;/p&gt;

&lt;p&gt;Some smartwatch providers are API backed, and these APIs allow an attacker to make it appear that the child was somewhere else but watch location pointing somewhere, and that's the whole point of the device.&lt;/p&gt;

&lt;p&gt;Here we are not making fun of any company, but we can evaluate our application standards based on their mistakes.    &lt;/p&gt;

&lt;p&gt;What happens after this? The watch company has worked hard, updated its system, fixed that issue, and returned to the market after one year. Security researchers took another look at their APIs, and they discovered something interesting !!&lt;/p&gt;

&lt;p&gt;In one of the API, there was a parameter called user grade.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fow0j6dont8g1gmn8bhox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fow0j6dont8g1gmn8bhox.png" alt="user[grade]" width="508" height="111"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If this parameter's value is 2, it works fine, no issues, but they figured out if the value change to 1, you become the Admin !!&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;![user grade admin image ](https://dev-to-uploads.s3.amazonaws.com/i/d8zeankidwirql02lqm1.png)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So this is the kind of fundamental issue, let us see one more relevant and common one.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Facebook has one beta version of its website [mbasic.facebook.com(&lt;a href="https://mbasic.facebook.com/)for"&gt;https://mbasic.facebook.com/)for&lt;/a&gt; testing all new features and stuff; in March 2016, one bug bounty hunter reported missing &lt;a href="https://developer.github.com/v3/#rate-limiting"&gt;rate-limiting&lt;/a&gt; for forget password endpoint. It means anybody can try every possible combination to get the password of a user. It is not too tricky also even there is already one HTTP status available.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Firryd68pnvlpyaz38l6b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Firryd68pnvlpyaz38l6b.png" alt="HTTP Status 409" width="650" height="124"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This point brings us our first security pitfall lack of rate-limiting.&lt;/p&gt;

&lt;h2&gt;
  
  
  No RATE LIMITING
&lt;/h2&gt;

&lt;p&gt;Rate limiting prevents malicious code from abusing legitimate/ illegitimate access to your API.&lt;/p&gt;

&lt;p&gt;Surprisingly enough, so many APIs have rate-limiting as a business feature because they use it for their freemium model, which means you can do some number of calls for some time and get a premium or paid account for some time further access. To prevent active abuse and data exploitation of your APIs, you should have rate-limiting as a security measure. Lack of API rate limiting can also expose other points of a system to access data.&lt;/p&gt;

&lt;p&gt;In Aug 2018, Hackers Stole the Personal Data of &lt;a href="https://threatpost.com/t-mobile-alerts-2-3-million-customers-of-data-breach-tied-to-leaky-api/136896/"&gt;2.3 Million T-Mobile Customers&lt;/a&gt; through one of the leaky APIs.&lt;/p&gt;

&lt;p&gt;T-mobile has used customer phone numbers as an identifier for their accounts, which makes sense to a phone company because phone numbers are supposed to be unique in the whole system and easy to work with then; why not !!  &lt;/p&gt;

&lt;p&gt;However, the problem is not the access data with a phone number, but the problem is  &lt;strong&gt;insecure direct object reference&lt;/strong&gt;, which has been around for ages in web applications now; it just takes a new form with  APIs.&lt;/p&gt;

&lt;p&gt;This point brings us to our next security pitfall lack of proper authorization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lack OF PROPER AUTHORIZATION
&lt;/h2&gt;

&lt;p&gt;Insecure direct object reference issue is if you are accessing something and the system is not verifying that you are allowed to access that particular object yes or no.&lt;/p&gt;

&lt;p&gt;So in T-mobile's case system endpoint has verified that you are authenticated or not, and if not, you are not allowed to access the resource fair enough. Once you are authenticated, then the magic starts; provide the phone number get the data boom!!, they have never checked whether you are the owner of the account or not.&lt;/p&gt;

&lt;p&gt;This is a very, very common authorization problem, and the reason why these problems exist because of tutorials like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffee7rd5duv7yi7t55z8a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffee7rd5duv7yi7t55z8a.png" alt="10 min Node.js tutorial" width="664" height="56"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am going to assure you in 10 min there is no security involved in it and which is ok because the tutorial doesn't focus on security, but it teaches how Rest API works, for example, there is an endpoint that takes an Id for reading a task or same goes to delete the task, etc. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzs0kinp73u5jh0wbvs61.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzs0kinp73u5jh0wbvs61.png" alt="read a task" width="453" height="151"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Few461a1zeg30489ssrwe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Few461a1zeg30489ssrwe.png" alt="delete a task" width="471" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Easy way to start right, no issues at all, but when you move this small todo app to production, you have to think about authentication. Next, step most of us will learn about how authentication works, and then we implement the check is user authenticate or not ??.&lt;/p&gt;

&lt;p&gt;Unless we react to thinking about, hey we not only have to worry about user authentication but also we need to think about whether this user has access to modify or delete this task, we have an authorization problem.&lt;/p&gt;

&lt;p&gt;The authorization problem is not that easy to solve. The application needs to know who the user and every API of the application should be aware of the user access.&lt;/p&gt;

&lt;p&gt;To solve the Authorization problem first, we need to know who the user is; I know it is a part of the authentication process. Still, it is imperative to propagate the user information to every API of the application in one way or another.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding authentication or some heading
&lt;/h2&gt;

&lt;p&gt;Back in the days, we had PHP applications like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fub2r3rk3ghwz8k5cj2xq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fub2r3rk3ghwz8k5cj2xq.png" alt="Client-Server" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have client, server, and session saved on the server, so as the application grows, we have multiple clients, servers and this architecture refer as a stateful application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq9dn52mcw8gaxrybmjap.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq9dn52mcw8gaxrybmjap.png" alt="multiple-client-server" width="550" height="1254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As the technology evolved, rest API-based systems became the trend, and people started moving towards stateless application sessions no longer stored on servers. Stateless systems are making sense if you building applications for thousands or millions of users. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fthw3awfhn6qsfq7n5f90.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fthw3awfhn6qsfq7n5f90.png" alt="Stateless-applications" width="800" height="818"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Server-side session data is not compatible with the REST stateless paradigm but still works well with small to medium-scale applications.&lt;/p&gt;

&lt;p&gt;The whole point of the above discussion is where you keep the user information, whether authentication or authorization.&lt;/p&gt;

&lt;p&gt;Where you keep this info is does matter, why because saving state on the server-side is a traditional way of doing and the server is considered charming, secure environment, attackers cannot easily reach to the server and change the information its like authentication valid for name Jhon changing it to something else it's complicated and if you can change this info, then you have breached the security. You can do whatever you want, not only changing the authentication property.&lt;/p&gt;

&lt;p&gt;However, movings things to the client-side is a bit tricky; that's precisely the point of stateless applications.&lt;/p&gt;

&lt;p&gt;It does not just take the state from the server and move it to the client, and you are done.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxpcvyr8xquxcj1xrve59.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxpcvyr8xquxcj1xrve59.png" alt="stateless-app" width="800" height="983"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In your applications, it has many impacts. It depends on how you handle this information on the client-side. The user state moved from a very secure, isolated environment to an easily accessible place where anybody can change whatever they want.&lt;/p&gt;

&lt;p&gt;You have no idea about the data which comes back it's trustworthy or not, before you make an authorization decision.&lt;/p&gt;

&lt;p&gt;In modern web applications, we often use &lt;a href="https://jwt.io/"&gt;JSON WEB TOKENS&lt;/a&gt; to solve this issue. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fey9j0jdi2smih0xjx4wo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fey9j0jdi2smih0xjx4wo.png" alt="JWT" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Usually, we use them in combination with OAuth and OIDC, not as a basic token. Here we will not discuss in detail &lt;a href="https://jwt.io/"&gt;JSON WEB TOKENS&lt;/a&gt; only brief.&lt;/p&gt;

&lt;p&gt;As you can see in the image left side is the actual token, and the right side purple color is the data that we can use later, and this data protected by a signature that ensures the integrity of the data. So once you receive the data, it can be verified by a server-side secret key, and you can decide because you have reliable data.&lt;/p&gt;

&lt;p&gt;To match the signature and other stuff will again fall back on us a developer, which can lead to several other issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  MISHANDLING CLIENT-SIDE SESSION DATA
&lt;/h2&gt;

&lt;p&gt;Client-side session data is easy to read and manipulate. You need to ensure confidentiality and integrity before using any of the session data.&lt;/p&gt;

&lt;p&gt;If you are a Java developer, you might write code like this from a prevalent library &lt;a href="https://github.com/auth0/java-jwt"&gt;Auth0 java-jwt&lt;/a&gt; easy to use, but if you know how to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fudq8p8g06q5ciy4hu7rf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fudq8p8g06q5ciy4hu7rf.png" alt="JWT-JAVA" width="800" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This example is not the correct way to use it here the step&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DecodeJWT jwt = JWT.decode(token);&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
 will take out the payload and will return your claim as an object to get user-related data, id, etc.&lt;/p&gt;

&lt;p&gt;The above can be if you have missed reading the library documentation or in your IDE you got the suggestion ohh, Decode, that is what I need to do which can lead to this type of critical issues. This issue will never be caught in testing unless you feed some malicious signature, so you have to think about security in the testing phase.&lt;/p&gt;

&lt;p&gt;Instead of just this simple code which only decodes the data, it could be implemented like this. You can also encrypt JWT before sending it to the client; more advanced libraries are available to support JWT encryption and can be a good idea.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftj0azox5y9hl9pvow3yy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftj0azox5y9hl9pvow3yy.png" alt="JWT-sig verification" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Things are not going to end here, so; please bear with me for some time; let's see how the JWT signature can be misused.&lt;/p&gt;

&lt;h2&gt;
  
  
  MISUSING THE JWT SIGNATURE SCHEME
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhcjx8e97ppq1d2d2h1hf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fhcjx8e97ppq1d2d2h1hf.png" alt="HMAC" width="716" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;HMAC stands for Hashed or Hash-based Message Authentication Code. So it's not a signature; it is a checksum that is used to generate the signature.&lt;/p&gt;

&lt;p&gt;You have the data, header, and payload (JWT), and the library will push this data to the HMAC function and provide a secret HMAC key, and the output comes as a random base64 encoded string doesn't mean anything. This is the key that we have to send to the client as data.&lt;/p&gt;

&lt;p&gt;When it comes back to the server, you do the same thing, push it to the HMAC function with the same secret key and match the output string.&lt;/p&gt;

&lt;p&gt;If it is the same, you know that the message has been signed before it is the same, coming back now.&lt;/p&gt;

&lt;p&gt;If they don't match, something has changed because the secret key is the same, then it must have been the modified data.&lt;/p&gt;

&lt;p&gt;We don't care what is changed; whether space is added or something else, throw it out because it is an invalid token.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgea8ae8ov6g7qsp4tx76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fgea8ae8ov6g7qsp4tx76.png" alt="HMAC function" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's continue this in the next blog API security Part-2 publishing soon. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>I did nothing for a day</title>
      <dc:creator>Sumit</dc:creator>
      <pubDate>Sun, 13 Sep 2020 08:21:17 +0000</pubDate>
      <link>https://dev.to/tech_sam/i-did-nothing-for-a-day-596m</link>
      <guid>https://dev.to/tech_sam/i-did-nothing-for-a-day-596m</guid>
      <description>&lt;p&gt;What I have observed &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I was able to breathe more deeply. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I was able to notice things around me which usually I don't.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is the pic which I took from my bathroom wall, from years which I didn't notice(sry for bad image quality 😇)&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6s1smj5f9fl6r6a00gtq.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6s1smj5f9fl6r6a00gtq.jpeg" alt="smile" width="800" height="726"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;My intensity of workout got increased and I was able to focus more, reason was &lt;code&gt;no meetings to attend&lt;/code&gt;, &lt;code&gt;no emails to reply to&lt;/code&gt; , the most important thing, &lt;code&gt;no coding&lt;/code&gt; ☺️ !!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Played with my cat&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fiyu7auqdj1upx75aquzh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fiyu7auqdj1upx75aquzh.jpg" alt="Baburao" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Planned to write this blog &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I felt so much change only in a day, I will try to do this more frequently and for a longer time.&lt;/p&gt;

&lt;p&gt;Comment down your nothing day story or if you have a plan to do the same !!&lt;/p&gt;

&lt;p&gt;Thank you for reading :) :)&lt;/p&gt;

</description>
      <category>digitaldetoxification</category>
      <category>nothingday</category>
      <category>nocodingday</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Performance matters</title>
      <dc:creator>Sumit</dc:creator>
      <pubDate>Tue, 05 May 2020 11:39:26 +0000</pubDate>
      <link>https://dev.to/tech_sam/performance-matters-2l69</link>
      <guid>https://dev.to/tech_sam/performance-matters-2l69</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7fhnxykm9sgbhq3553pp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7fhnxykm9sgbhq3553pp.jpg" alt="Performance" width="800" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Good performance starts with good code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sometimes a small change in your code can make a significant amount of performance improvement.&lt;br&gt;
So let not your code stink, be careful next time while you write code.&lt;/p&gt;

&lt;p&gt;The API of Optional typically has two methods that can cause confusion: orElse() and orElseGet().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1.  public T orElse(T other)
2.  public T orElseGet(Supplier&amp;lt;? extends T&amp;gt; other)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clearly, orElse() takes any parameter of a type T whereas orElseGet() accepts a functional interface of type Supplier that returns an object of type T.&lt;/p&gt;

&lt;p&gt;Now, based on their &lt;a href="https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html#orElse-T-"&gt;Javadocs&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;. orElse(): returns the value if present, otherwise return other&lt;br&gt;
. orElseGet(): returns the value if present, otherwise invoke other and return the result of its invocation&lt;/p&gt;
&lt;h3&gt;
  
  
  orElse()
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;orElse()&lt;/strong&gt; is evaluated even when having a non-empty Optional.&lt;br&gt;
For example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String name = Optional.of("dev.to")
  .orElse(processData());

public String processData() {
    LOG.info("process data method - start");
     
    // DB process/update complex business logic 
     
    LOG.info("processData method - end");
    return "processed string";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On executing our code, we'll find below messages printed in the console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;process data method - start
processData method - end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variable name will hold &lt;strong&gt;dev.to&lt;/strong&gt; at the end of the code execution.&lt;/p&gt;

&lt;p&gt;With it, we can easily infer that the parameter of &lt;strong&gt;orElse()&lt;/strong&gt; is evaluated even when having a non-empty Optional. It can easily cause Hugh performance downgrade if &lt;code&gt;else&lt;/code&gt; part is having some DB processing or complex business logic.&lt;/p&gt;

&lt;h3&gt;
  
  
  orElseGet()
&lt;/h3&gt;

&lt;p&gt;Now, let's try writing similar code using &lt;strong&gt;orElseGet()&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String name = Optional.of("dev.to")
  .orElseGet(() -&amp;gt; processData());

public String processData() {
    LOG.info("process data method - start");

    // DB process/update heavy processing 

    LOG.info("processData method - end");
    return "processed string";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code will not invoke processData() method.&lt;/p&gt;

&lt;p&gt;Using &lt;strong&gt;orElseGet()&lt;/strong&gt; for our case will, therefore, save us some time involved in computing.&lt;/p&gt;

&lt;p&gt;So to summarize this blog we can considering factors involve.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What if the method would execute some additional logic? E.g. making some DB inserts or updates&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Even when we assign an object to orElse() parameter&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;String name = Optional.of("dev.to")&lt;br&gt;
  .orElse("Other");&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;we're still creating “Other” object for no reason&lt;/p&gt;

&lt;p&gt;And that's why it is important for us to make a careful decision among orElse() and &lt;code&gt;orElseGet()&lt;/code&gt; depending on our needs – by default, it makes more sense to use &lt;code&gt;orElseGet()&lt;/code&gt; every time unless the default object is already constructed and accessible directly.&lt;/p&gt;

</description>
      <category>java</category>
      <category>performance</category>
      <category>optional</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Let's revisit Java in 2019</title>
      <dc:creator>Sumit</dc:creator>
      <pubDate>Sat, 19 Oct 2019 15:25:03 +0000</pubDate>
      <link>https://dev.to/tech_sam/let-s-revisit-java-in-2019-3o8c</link>
      <guid>https://dev.to/tech_sam/let-s-revisit-java-in-2019-3o8c</guid>
      <description>&lt;p&gt;It's been 6 years from now since Java 8 was released and people are still not able to digest the features of it, wasn’t Java 8 a fantastic update to the language?&lt;/p&gt;

&lt;p&gt;Lambdas and streams were a huge change and have helped to improve Java developers’ productivity and introduce some functional ideas to the language.&lt;/p&gt;

&lt;p&gt;Then the new guy came into the town Java 9, and although the module system is really interesting for certain types of applications, but  uncertainty around how painful it might be to migrate to Java 9 left many applications taking a wait-and-see approach, happy with Java 8 and some are still living with the old buddies Java 5-7.&lt;/p&gt;

&lt;p&gt;But now Java has a new version every six months, and suddenly Java 13 is here. We’re all still on Java 8, wondering whether we should move to a later version, which one to choose, and how painful it might be to upgrade.&lt;/p&gt;

&lt;p&gt;In this blog we’ll look at:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Why upgrade from Java 8, including language features from Java 9, 10, 11, 12, 13?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What sorts of issues might we run into if we do choose to upgrade?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How the support and license changes that came in with Java 11 might impact us?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since Java 11, there have been a few concerns around, I don't want to pay for Java.&lt;/p&gt;

&lt;p&gt;I want to discuss a bit about this, because a lot of people are super happy with Java 8, thank you very much. I think I'll just stay here. I've got lambdas and streams. It's all I ever wanted from my language. I don't need modularity, so I'm not going to go beyond Java 8.&lt;/p&gt;

&lt;p&gt;This is what I am hearing and finding everywhere from people who are at least some concern about their tech stack. This doesn't even represent the people who are using 7, 6, or even, heaven forbid, earlier than 6.&lt;/p&gt;

&lt;p&gt;Lot's of changes that happened in the last couple of years news-wise that you need to be aware of if you're running Java inside your organizations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Releases
&lt;/h2&gt;

&lt;p&gt;Firstly, &lt;em&gt;Java has moved to a six-month release cycle&lt;/em&gt;.&lt;br&gt;
In the old days, we would get Java every two years, three years or sometimes six or seven years between versions of Java, which is one of the reasons why I think enterprises loved it so much because it's nice and stable.&lt;/p&gt;

&lt;p&gt;But now, since Java 9, we have releases every March and every September like clockwork, and this is a much better way of working.&lt;/p&gt;

&lt;p&gt;We know this from doing continuous delivery and continuous deployment. If we say we're going to release on a specific date, we just release the features that were ready then. And then if they're not ready at that point, we release them in the next release. We just have this nice, predictable release cadence.&lt;/p&gt;

&lt;p&gt;As a developer, we know it's a pain in the neck to support something, more than one version of something, at the same time. Same thing applicable to Oracle also and obviously Oracle didn't want to support every one of these releases for three years because, at some point, they'll be supporting like six or seven different versions of Java.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Instead, with the six-monthly releases, each release will be supported for the six months of their life.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By support, I mean having updates available, so updates for 9, 10, and so on and so forth for six months, until the next release comes out.&lt;/p&gt;

&lt;p&gt;Obviously, not everyone wants to upgrade their version of Java every six months. So here is a catch, every three years one of these releases will be designated a long term support release, specifically &lt;em&gt;Java 11&lt;/em&gt; and I assume &lt;em&gt;Java 17&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Java 8 is also a long term support release. You get sort of mini releases every six months, 9, 10, and then you get long term support releases every three years, so 11. And that explains people are on either 8 or 11. Because if you are using 9, you should have migrated to 10. And if you are on 10 you should have gone to 11, because now 9 and 10 are no longer supported.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The OpenJDK is the same as the Oracle JDK, and that includes the commercial features that you used to have to pay for in the Oracle JDK.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are a bunch of different Open JDK vendors to choose from some of them are &lt;a href="https://www.azul.com/downloads/zulu-community/?&amp;amp;architecture=x86-64-bit&amp;amp;package=jdk"&gt;Zulu&lt;/a&gt;, &lt;a href="https://adoptopenjdk.net/"&gt;AdoptOpenJDK&lt;/a&gt;, &lt;a href="https://aws.amazon.com/corretto/"&gt;Amazon Corretto&lt;/a&gt;, etc. So Oracle is not the only game in town.&lt;/p&gt;

&lt;p&gt;Because of these different options, it lets you slowly migrate from 8 to 11, to 17 with a bit of overlap. You can actually see it says the end of availability for Java 8 is at least September 2023. So some of you are going to take away from this blog, &lt;em&gt;We don't need to upgrade from Java 8 until 2023.&lt;/em&gt; Fine, but you're going to have a lot of pain in a few years' time.&lt;br&gt;
So the question is now that sounds scary and complicated.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why should I bother migrating from Java 8?
&lt;/h2&gt;

&lt;p&gt;We are developers and technical people, and what we care about is the language features.&lt;/p&gt;

&lt;p&gt;People who are using versions of Java later than 8, which are the features they use the most? Which ones are the most interesting?&lt;br&gt;
Here we are not going to discuss detail about these features, that we can plan for some other time.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.oracle.com/javase/9/jshell/introduction-jshell.htm#JSHEL-GUID-DA9FA090-7015-4F30-BBD0-5F6ED0EBDF91"&gt;JShell&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With the help of JShell, you can able to run small snippets of Java from the command line, which we could never do before because we had to have a whole class with public static void main(), blah, blah. But now we can do, including tab completion, we can just run stuff from the command line. And you see, you get all your nice tab completion there. And you don't need semicolons, progress. You could do a bunch of other stuff. You can, obviously, define variables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PnSHJ4j8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/wnsxit89fmpmf3t7xepu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PnSHJ4j8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/wnsxit89fmpmf3t7xepu.png" alt="Jshell" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the nice things about using JShell is you can mess around with the new features without having to create a whole class or testing framework.&lt;/p&gt;

&lt;p&gt;You can run scripts and things like that. So it's kind of nice. I'm not really sure how many people are really using effectively scripting for Java. But it turns out that a lot of people are finding it quite useful. People were happy to see that JShell is built into the language. &lt;em&gt;You can just kind of use it to try stuff out as early as possible&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;One of the nice things about JShell, as you saw, it's like an independent command line thing. You don't actually need to do anything with your existing applications to start using it. You can just download Java 11, or Java 12,13 if you want, and use JShell completely independently from anything with the rest of your application. It allows you to sort of get started, get up and running early on and quickly without impacting anything that you have at the moment.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://openjdk.java.net/jeps/286"&gt;Var&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most of you probably know of, or have used var.Now, with var, it's going to use the type information obviously on the right to determine what the type is. Var doesn't mean dynamic typing, by the way; it just means you don't have to type the types on both sides of the equal sign.&lt;/p&gt;

&lt;p&gt;Var is not like a magic keyword, you just put it everywhere and say, "Let's just get rid of all the types on the left hand side." It's something to think about. You use it when it makes your code easier.&lt;/p&gt;

&lt;p&gt;The use of var also makes your code concise by reducing duplication, e.g. the name of the Class that comes in both right and left-hand side of assignments as shown in the following code snippet:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ByteArrayOutputStream bos = new ByteArrayOutputStream();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here, ByteArrayOutputStream repeats twice. We can eliminate that by using the var feature of Java 10 as shown below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var bos = new ByteArrayOutputStream();&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://openjdk.java.net/jeps/269"&gt;Factory methods for collections&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My favorite feature from Java 9 is the convenience factory methods for collections. This is one of the things that gets used by a bunch of people.&lt;/p&gt;

&lt;p&gt;We're going to look for Java 9. Obviously, this came into Java 9. For all of you using Java 8, in the olden days, we would declare a list, a set of values like this. Your &lt;code&gt;Arrays.asList()&lt;/code&gt;, and you sort of use it as if it was an &lt;em&gt;immutable, unmodifiable list&lt;/em&gt;. But actually it's not, because you can't add to that list, but you can change the individual elements on that list. So it's actually not unmodifiable, but we all used it as if it was. We have to wrap it inside an unmodifiable list to make it unmodifiable. In Java 9, you don't have to do that. You call &lt;code&gt;List.of()&lt;/code&gt; , and it's much more readable.&lt;/p&gt;

&lt;p&gt;It's kind of nice for a list. It's really nice for a set because creating a set was a bit of a pain. You have a list, and then you put it in a set, and then you wrap it in an unmodifiable set. I don't understand why this feature wasn't in the language earlier. Now, you just say &lt;code&gt;Set.of()&lt;/code&gt; and you will get an unmodifiable set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set&amp;lt;String&amp;gt; set = Collections.unmodifiableSet(new HashSet&amp;lt;String&amp;gt;() {{
     add("foo"); add("bar"); add("baz");
}});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;can be used now as&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Set&amp;lt;String&amp;gt; set = Set.of("foo", "bar", "baz");&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Same thing is applicable to &lt;code&gt;Map&lt;/code&gt; also.&lt;/p&gt;

&lt;p&gt;In Java 10, one of the things that came in is the ability to collect into these unmodifiable lists. That's really useful. You can just straight away change your streams to collect into unmodifiable lists, sets, etc.&lt;/p&gt;

&lt;p&gt;Another new feature that came in in Java 9, is new methods on the Stream API. This was a feature that I thought was a little bit missing from Java 8, the ability to do things like process this stream until some condition is met. This is &lt;a href="https://docs.oracle.com/javase/9/docs/api/java/util/stream/Stream.html#takeWhile-java.util.function.Predicate-"&gt;.takeWhile()&lt;/a&gt;, the other example is &lt;a href="https://docs.oracle.com/javase/9/docs/api/java/util/stream/Stream.html#dropWhile-java.util.function.Predicate-"&gt;.dropWhile()&lt;/a&gt;, so ignore this stream until some condition is met. So it's just a nice little addition to the language for working with streams.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Stream&amp;lt;String&amp;gt; stream = Stream.of("sam", "sumit", "jhon","nancy");
 List&amp;lt;String&amp;gt; list = stream.takeWhile(name -&amp;gt; (name.charAt(0) == 's'))

                  .collect(Collectors.toList());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the output of this code will be &lt;code&gt;[sam,sumit]&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Stream&amp;lt;String&amp;gt; stream = Stream.of("sam", "sumit", "jhon","nancy");
    List&amp;lt;String&amp;gt; list = stream.dropWhile(name -&amp;gt; (name.charAt(0) == 's'))

                  .collect(Collectors.toList());

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the output of this code will be &lt;code&gt;[jhon, nancy]&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/util/Optional.html"&gt;Optional methods&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then over the course of Java 9, 10, and 11, we've been getting additional methods on optional. I actually think this is one of the most interesting things about the most recent versions of Java.&lt;/p&gt;

&lt;p&gt;Java 8 had optional. Optional is good. It's a really nice way of saying, as a return type from an method, saying, "You might get something. You might not."&lt;/p&gt;

&lt;p&gt;Don't misuse it in terms of having it for fields, and for parameters, and all the rest of it. It's really there just for when you ask for something like, "Find me something." Optional can say, "You got something," or, "You didn't." With Java 8, you can work with it in a fairly simple way. You can say &lt;code&gt;.ifPresent()&lt;/code&gt;, or &lt;code&gt;.isPresent&lt;/code&gt;, and &lt;code&gt;.get()&lt;/code&gt;. And it's kind of fine, but the recent methods that have been added on 9, 10, and 11 make it a little bit even easier to use.&lt;/p&gt;

&lt;p&gt;For example, when you have to use &lt;code&gt;Optional.isPresent()&lt;/code&gt;, and you have to do a &lt;code&gt;.get()&lt;/code&gt;, and then an else- which you don't have to, because you could have done a &lt;code&gt;.ifPresent()&lt;/code&gt; there, but you still have the else hanging around which is a bit clumsy. I found that optional was a bit difficult to work within 8.&lt;/p&gt;

&lt;p&gt;But now, you can just give two lambda expressions. So you either do that if it's present, or you do something else if it's not present. That's one of the nice things. That's Java 9. You’ve got &lt;code&gt;.or()&lt;/code&gt; on Java 9 as well, which gives you an alternate optional. So you either return this optional value or return a different optional value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; blog.ifPresentOrElse(  
  this::publish,  
  this::notifyThatNothingWasPublished
 );

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html"&gt;HTTP client&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Java 11 comes with a built in HTTP client. Built in HTTP client will solve our headaches, so you don't have to use any dependencies. But also, it's non-blocking reactive streams, HTTP 1 and 2. So this is something that a lot of people are interested in from a Java 11 point of view, especially in this current world of asynchronous reactive programming.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://openjdk.java.net/projects/jigsaw/"&gt;Project Jigsaw&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Java 9 had Jigsaw, which everyone is very excited about it or not. And of course, we're supposed to call it the Java Module System, not Jigsaw. So it is useful for a bunch of people specifically, again, for library developers because they can encapsulate stuff that you're not supposed to be able to touch. That's the point. But it also can be useful for enterprise developers who want an excuse or a mechanism to actually properly separate the concerns inside their applications.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.oracle.com/en/java/javase/11/tools/jlink.html"&gt;JLink&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The most interesting thing to me I think about the module system is it allows us to do things like have JLink. I think, is very interesting. This allows you to package up your application and just the bits of Java that you want, and create a much smaller deployable, and deploy it into the cloud. For example, with the JDK being modularized, there's a whole bunch of modules you could be using. But if you're just using java.util or java.logging, like two or three of those modules, you use JLink to create a single deployable with your application and just the bits of Java that you want. They can be much, much smaller.&lt;/p&gt;

&lt;p&gt;This is not the end of the world it is just I don't want to make this blog a marathon 😌.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reason to upgrade
&lt;/h2&gt;

&lt;p&gt;The business doesn't care about language features. We care about language features because it makes our job easier.&lt;/p&gt;

&lt;p&gt;I say we- I'm assuming that we're all developers, or developer-minded. So you can't sell the business on upgrading to Java 13 because of var, for example, they just don't care. But what they do care about is things like performance.&lt;/p&gt;

&lt;p&gt;So generally speaking, each version of Java is generally faster for a number of different reasons. Anytime you upgrade, even if you don't make any changes, even if you don't make use of anything, you generally find that the performance of your application is better&lt;/p&gt;

&lt;p&gt;Obviously, test, measure, see if it's true or not, but often you get free performance improvements.&lt;/p&gt;

&lt;p&gt;Specifically, in the last few versions, there's been a lot of optimization, some memory use. For example - that's &lt;a href="https://docs.oracle.com/javase/9/gctuning/garbage-collector-implementation.htm#JSGCT-GUID-C2CA24AD-DC01-4B31-A868-F7DAC7E3BF4D"&gt;garbage collectors&lt;/a&gt;, and we used things like the way that strings are represented. Particularly if you're running in the cloud and you care about memory use.&lt;/p&gt;

&lt;p&gt;There have been a lot of changes to the garbage collector. In Java 9, the default garbage collector is G1. And then a bunch of changes went in to help improve the performance of G1 even further.&lt;/p&gt;

&lt;p&gt;If you care about the garbage collection, obviously, people tend to go, "Performance equals garbage collection in Java." It's an element of it, but it's not the only aspect of performance. But there are a lot of changes there. Coming in later, we have even more different types of garbage collectors, more improvements to those garbage collectors, and so on. So, again, these are the sorts of things that if these garbage collectors and these changes work for you, you get some free performance improvements moving forward.&lt;/p&gt;

&lt;p&gt;Obviously, what the business really cares about is cost. Now, I believe that moving forward to a later version of Java can help reduce costs of the company, by which I mean actual money type costs, in terms of things like using JLink, in terms of things like better performance, lower memory usage, and so forth.&lt;/p&gt;

&lt;p&gt;So you can reduce costs. But there's also another cost which I think is important. If your organization is trying to hire Java developers, which most organizations are at any point in time if they have a big Java shop, and if you're going to be stuck on an older version of Java for a long period of time, it will be more difficult to attract developers going forward. At the moment it's fine because they're probably fine working on Java 8. But going forward, people are not going to be interested in working on legacy systems going forward. So I guess that's kind of a personal thing from the developer's point of view.&lt;/p&gt;

&lt;p&gt;The other reason which I think is really interesting to move on and migrate now is to get yourself on the six-month release train before it gets away from us. Because we may be worried about getting over the hump of Java 9 to Java 10. But if we leave it much longer, it's just going to get worse and worse. That big difference between Java 8 and Java 17 is just going to be a very difficult bridge to span, a gap to bridge.&lt;/p&gt;

&lt;p&gt;So I think it's worth trying to get onto 11 now so that then we can start thinking about testing against each of these six-monthly releases. Even if we stick on 11 and we don't plan to migrate to 12, 13, 14, we plan to migrate to 17, we can be running each of these six-monthly releases in CI to make sure that we stay up to date for as long as possible.&lt;/p&gt;

&lt;p&gt;If you try and migrate to Java 17, it's going to be very painful, particularly since Oracle has said they are going to start deleting stuff. Deprecated means deprecated. There may only be a year's worth of notice between deprecating something, and actually removing it from the language. So we need to get onto this release train now and do it more frequently.&lt;/p&gt;

&lt;h2&gt;
  
  
  In Summary
&lt;/h2&gt;

&lt;p&gt;Java is changing and it's changing much faster than it used to. It's no longer the nice, slow, and stable enterprise type language that we're used to. Modern Java can help you. This is a good thing. The recent versions of Java have focused on things like reducing boilerplate, increasing readability, but also, of course, things like performance is always improved with each release of Java.&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>Take a walk with OAuth 2.0</title>
      <dc:creator>Sumit</dc:creator>
      <pubDate>Sun, 25 Aug 2019 12:48:02 +0000</pubDate>
      <link>https://dev.to/tech_sam/introduction-to-oauth-2-0-1an2</link>
      <guid>https://dev.to/tech_sam/introduction-to-oauth-2-0-1an2</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8kj3ivyuetyy49ikelkc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8kj3ivyuetyy49ikelkc.png" alt="OAuth2.0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Recently I got a chance to work on OAuth 2.0 and I have noticed that there is so much complexity and confusion about &lt;code&gt;OAuth 2.0 and OpenID connect&lt;/code&gt; over the internet.&lt;/p&gt;

&lt;p&gt;The reason behind it is that it's a difficult protocol to understand, tons of jargons and terminologies and there is a lot of confusion about it online.&lt;/p&gt;

&lt;p&gt;When I have started to learn about OAuth 2.0 and OpenId connect I didn't find a single source of truth and there is a plethora of blogs and everybody on StackOverflow seems to be explaining it in their own way to implement it.&lt;/p&gt;

&lt;p&gt;If you have ever felt confused, overwhelmed then you are not the only one, pretty much everybody has. In this blog, I will try to make things a little bit less intimidating and in the comments, you can let me know if it makes sense.&lt;/p&gt;

&lt;p&gt;Why when we have a concrete &lt;a href="https://tools.ietf.org/html/rfc6749" rel="noopener noreferrer"&gt;spec&lt;/a&gt; but so many different interpretations about how to use it? that doesn't happen with a protocol like HTTP and there is a pretty correct and concrete way to use but with OAuth, there is some fuzziness in the implementation which makes it more difficult and creates confusion on how to use it.&lt;/p&gt;

&lt;p&gt;So before explaining about OAuth and OpenId, I just want to set a stage for simple login and forms authentication which is the most basic type of authentication on the web where user enters username/email and password, the request goes to the server and the server talks to the database and verifies the username and password hopefully, hashed one 😉.&lt;/p&gt;

&lt;p&gt;If the verification was successful then the server sends a cookie to the web browser to keep track of the user.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3m55hquzkm1qfmqp91vq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3m55hquzkm1qfmqp91vq.png" alt="Basic Form Authentication"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the industry is moving away from this kind of homegrown solution, this simple form authentication has nothing to do with OAuth but I just want to let you know that this is what we are going to compare with.&lt;/p&gt;

&lt;p&gt;So there are a couple of downsides of this approach like&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Security &lt;/li&gt;
&lt;li&gt;Maintenance &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because you are responsible for maintaining the authentication system there is only your server-side code which will talk to the database and verify the password and all. You should be always aware of new security standards and best practices like hashing, encryption and storing user information securely, etc.&lt;/p&gt;

&lt;p&gt;Let's go back in time 2006-07,  Applications and websites back then also had several use cases such as Login, Authentication, Authorization, etc &lt;br&gt;
so we can combine these cases and call it Identity use cases.&lt;/p&gt;

&lt;p&gt;Identity use cases(pre-2010)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple login (forms and cookies)&lt;/li&gt;
&lt;li&gt;Single sign-on across sites (&lt;a href="https://www.varonis.com/blog/what-is-saml/" rel="noopener noreferrer"&gt;SAML&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Mobile login (user should stay logged in if the app is closed also &lt;code&gt;long living sessions&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Delegated authorization (????)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here the term Delegated authorization is the Genesys of OAuth protocol. &lt;br&gt;
Despite sounding very boring this is the thing I am going to focus on.&lt;/p&gt;

&lt;p&gt;You might be aware of delegated authorization and which is something you interact every day, without actually knowing what it is. It is a common pattern now but it was not 10 years back.&lt;/p&gt;

&lt;p&gt;Delegated authorization is the process where we let sepecific websites access our data without actually giving away the credentials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F29ueymi41brm8p169gj4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F29ueymi41brm8p169gj4.png" alt="Delegated authorization Sample"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So back then there was no good way to solve this problem and one company called Yelp tried to solve this problem but in a really bad way &lt;br&gt;
at the end of registration Yelp asked  users  hey you want to share Yelp with your Gmail or Yahoo contacts for sign up or promotions etc,&lt;br&gt;
for this, they want user's actual Gmail email address and password it means its like Yelp login to user's Gmail account grab user's contacts sends email to them, then logout and throw away the password and promise not to do anything evil 😱&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F89t15zdxblvhugd9nknj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F89t15zdxblvhugd9nknj.png" alt="Yelp Delegated authorization Solution"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For many people, their Gmail or Yahoo account was their main email accounts and key for everything they have like bank details, finances, password resets, etc. So it is a really bad idea to give their password randomly to any app or website.&lt;/p&gt;

&lt;p&gt;Here I am not targeting Yelp to design this type of solution it's just a good example to illustrate what was the problem then how they didn't have the proper way to solving the problem. &lt;/p&gt;

&lt;p&gt;Today we are having a better way to solve this problem using OAuth protocol like the image above where Gitlab wants to access Github user information. &lt;/p&gt;

&lt;p&gt;Now we will see how Yelp should have been solved this problem using OAuth.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwmmd6mewjg93wobcdlid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwmmd6mewjg93wobcdlid.png" alt="Delegated authorization with OAuth 2.0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nowadays we are having one link/button mostly on every application something like &lt;code&gt;connect with google&lt;/code&gt;, what happens when user will click on this button user will put into OAuth flow and ultimate result of this, the application can access the user's authorized information. &lt;/p&gt;

&lt;p&gt;User can ensure that the application which wants the contact access can only be able to access contacts not like delete the contact, send an email or view the photos on google photos and drive information, etc.&lt;/p&gt;

&lt;p&gt;When user will click on &lt;code&gt;connect with google&lt;/code&gt; button browser will redirect to a google login page like &lt;code&gt;account.google.com&lt;/code&gt; this is a little bit better than the previous solution because the user is providing the password to google though not to Yelp or somebody else. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd75wfnez2mkcjrgzbesw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fd75wfnez2mkcjrgzbesw.png" alt="Delegated authorization with OAuth 2.0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Assume now the user logged in successfully, then one prompt will appear as this application Yelp wants to access your list of information which includes your public profile or contact details etc, are you sure you want to allow to access Yelp this information.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3460x773smxeuwvtlda8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3460x773smxeuwvtlda8.png" alt="Consent"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now User explicitly has consent to whatever they're granting access to,  that's important so he doesn't get tricked into like agreed to something that he doesn't know.&lt;/p&gt;

&lt;p&gt;So if the user clicks No, then we are done nothing interesting happens here and flow will restart again but suppose if the user clicks on Yes then the browser one more time redirect back to the application, back to where it started to a special place in the application called a callback or a redirect callback or redirect URI that again we will discuss later in the blog.&lt;/p&gt;

&lt;p&gt;Then with a little bit of magic that application which is Yelp in our case allowed to talk to some other API  say like google contacts API and Yelp usually don't have access to this API but now it has something(&lt;code&gt;access_token&lt;/code&gt;) which this application got when the user clicks on Yes button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fuyp4o4szb6q0m9qv4flv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fuyp4o4szb6q0m9qv4flv.png" alt="OAuth 2.0 magic"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, below are the things which go into this magic.&lt;/p&gt;

&lt;h3&gt;
  
  
  OAuth 2.0 terminology
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Resource Owner&lt;/li&gt;
&lt;li&gt;Client&lt;/li&gt;
&lt;li&gt;Authorization Server&lt;/li&gt;
&lt;li&gt;Resource Server&lt;/li&gt;
&lt;li&gt;Authorization Grant&lt;/li&gt;
&lt;li&gt;Redirect URI&lt;/li&gt;
&lt;li&gt;Access Token&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A resource Owner is a fancy way of talking about you and me as a user who is clicking on Yes button and sitting in front of computer who owns the data which application Yelp wants to access, in this context I am the resource owner who is having Gmail account and contacts and Yelp is want to access my Gmail contacts. &lt;/p&gt;

&lt;p&gt;A client is just a way to refer to the application in this case Yelp is the client, the application that wants the resource owner data basically.&lt;/p&gt;

&lt;p&gt;An authorization server is a system which resource owner can use to say yes, I authorized this permission and I authorized this to happen in this case authorization Server is &lt;code&gt;accounts.google.com&lt;/code&gt;.&lt;br&gt;
If you search on google term &lt;a href="https://support.okta.com/help/s/article/What-is-an-Authorization-Server" rel="noopener noreferrer"&gt;authorization server&lt;/a&gt; this is what you will get 😧 !! and this why I am writing this blog to make things a little bit more clear.&lt;/p&gt;

&lt;p&gt;A resource server is different from the authorization server, resource server is the API server which holds the data that the client wants to get access, in this case, Google contact API is the system which holds my contact. &lt;/p&gt;

&lt;p&gt;Sometimes authorization server and resource server together kind of melded into the same system but many time they separate.&lt;/p&gt;

&lt;p&gt;The whole point of OAuth flow is going over to the authorization server, coming back to the client is just to get something called authorization grant and the authorization grant is the thing that proves that  I have clicked on Yes or I consent to this level of permission or I allow you to have to access of my Gmail contacts.&lt;/p&gt;

&lt;p&gt;When the authorization server redirects back to the client application it kind of needs to know where to redirect back this is called callback or sometimes it is called redirect URI, it is just where should I end up at the end of this flow if the users click on Yes where they need to go next.&lt;/p&gt;

&lt;p&gt;I mentioned above the authorization grant is the point of this whole flow well but at an even higher level, the thing the client really needs is something called access token.&lt;br&gt;
An access token is going to be the way the key that the client uses to get into whatever the data user has granted access to or granted permission to on the resource server. &lt;/p&gt;

&lt;p&gt;Pheww so much information, I think you are getting confused and overwhelmed till this time if you are reading till now and if you are ready to show little bit patience your all doubts and confusion will clear in a bit.&lt;/p&gt;

&lt;p&gt;Let's see the diagram above which I have described earlier with all these jargons.&lt;/p&gt;

&lt;p&gt;Now we will start the flow again with me the resource owner who is sitting on the client website Yelp and I clicked on the &lt;code&gt;connect with google&lt;/code&gt; button and then what happens is I will redirect to this authorization server which is accounts.google.com in this case but it could be the Facebook authorization server or authorization server hosted by Octa or it could be somebody else .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg1t6bkmip7mhy1riy451.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fg1t6bkmip7mhy1riy451.png" alt="Flow-1 with jargon"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Right at the beginning of this flow when the client is redirecting over the authorization server its already passing some kind of the configuration information that the authorization server needs, so it's saying hey when you are done assuming everything is successful here is the URI where I want you to redirect back at the end. So we have to pass the redirect URI at the very beginning and we also have to provide some other information such as what type of authorization grant do we want.&lt;/p&gt;

&lt;p&gt;There are actually few different types of an authorization grant, in this case, we will be going to use a most simple type of authorization grant called code grant or authorization code grant because we are requesting a code and it is called authorization code flow. &lt;/p&gt;

&lt;p&gt;So now the authorization server prompts the login, consent to that permission all that good stuff then redirects back to the place specified at the beginning the redirect URI and redirect with something called authorization code because that's what we ask for at the beginning.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4zp6k9uheu0lup0bmejs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4zp6k9uheu0lup0bmejs.png" alt="Flow-2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the client can't do a whole lot with that authorization code, in fact, there's only one thing that the client can do at all with authorization code which is to go back to the authorization server one more time and exchange this authorization code with &lt;code&gt;access token&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqqtovnzm1y3316gdhts7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fqqtovnzm1y3316gdhts7.png" alt="Flow-3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After getting the access token, now the client Yelp can do what they actually want us to do in the first place which is going to the resource server &lt;code&gt;contacts.google.com&lt;/code&gt; and ask for the user contacts.&lt;/p&gt;

&lt;p&gt;Normally resource server will not allow to accessing the user's contacts but in this case, the client is attaching the access token in the request and this proves that user said that it is ok for the resource server to access contact information.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fy8hyrqu8111368h6aqyg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fy8hyrqu8111368h6aqyg.png" alt="OAuth 2.0 flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if the client tried to do something else say not retrieve my contacts but delete all my contacts, in this case, resource server says ok you have an access token but it doesn't mean that you can do just anything, the user has given you only read-only access to the contacts.  &lt;/p&gt;

&lt;p&gt;So access token grants access to the client to do specific things but how does the client specify what are the things it wants to do??&lt;/p&gt;

&lt;p&gt;Let's add some more terminologies.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scope&lt;/li&gt;
&lt;li&gt;Consent&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An authorization server is having a list of scopes based on the client needs, for example, read-only access to contact.&lt;/p&gt;

&lt;p&gt;Too much, ok I got it, let's continue about scopes and consent in the next blog. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Follow me on &lt;a href="https://medium.com/@tech_sam" rel="noopener noreferrer"&gt;Medium&lt;/a&gt; and &lt;a href="https://dev.to/tech_sam"&gt;Dev.to&lt;/a&gt; to know more about tech.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>oauth2</category>
      <category>authentication</category>
      <category>security</category>
    </item>
    <item>
      <title>Dev to Production Part -1</title>
      <dc:creator>Sumit</dc:creator>
      <pubDate>Sun, 28 Apr 2019 09:49:31 +0000</pubDate>
      <link>https://dev.to/tech_sam/dev-to-production-part-1-ig9</link>
      <guid>https://dev.to/tech_sam/dev-to-production-part-1-ig9</guid>
      <description>&lt;p&gt;The other day I was just lying down in my office chair and pretending to be super busy 😉, I was building a &lt;a href="https://jenkins.io/doc/" rel="noopener noreferrer"&gt;Jenkins&lt;/a&gt; release for one of our Spring-Boot application. My colleague was just passing from there and to spend some time I asked him, do you know what I am doing right now? he told you are making a plan to get Iron man to earth.&lt;/p&gt;

&lt;p&gt;As you know this is not real. I asked him what will happen after you push your code?. I got to know that he was not aware of the process after pushing the code. I thought why not write a blog and explain to my innocent colleague, friends and the other people who just push the code and waiting to get the ticket for the end game. So folks just take a chair and grab a beer here is the start of the end game.&lt;/p&gt;

&lt;p&gt;Soon I will update the source code at &lt;a href="https://github.com/Earth-43/Thanos" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The whole life cycle of developing something and get a release to a production environment is called CI/CD pipeline that stands for Continuous Integration and Continuous Delivery.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Continuous Integration (CI)&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;CI is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Continuous Delivery (CD)&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;CD is the natural extension of Continuous Integration: an approach in which teams ensure that every change to the system is releasable and we can release any version at the push of a button. Continuous Delivery aims to make releases faster and boring, so we can deliver frequently and get fast feedback on what users care about.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;a href="https://www.excella.com/insights/what-is-continuous-integration" rel="noopener noreferrer"&gt;continuous integration&lt;/a&gt; and deployment (CI/CD) pipeline is such an important aspect of a software project that it saves a ton of manual, error-prone deployment work. It results in higher quality software for continuous integration, automated tests, and code metrics. Ultimately this facilitates better software that can be released more frequently.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Faaldvilyo73oy9m0raww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Faaldvilyo73oy9m0raww.png" alt="cd/ci"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are a plethora of CI/CD products available out there, such as ones you can use in the cloud via software as a service (SaaS) or self-hosted ones. Some examples of hosted solutions are &lt;a href="https://codeship.com/" rel="noopener noreferrer"&gt;CodeShip.io&lt;/a&gt; and &lt;a href="https://travis-ci.org/" rel="noopener noreferrer"&gt;TravisCI&lt;/a&gt;, and self-hosted examples are &lt;a href="https://www.excella.com/insights/teamcity-vs-jenkins-better-continuous-integration-server" rel="noopener noreferrer"&gt;TeamCity,Jenkins&lt;/a&gt; and &lt;a href="https://www.gocd.org/enterprise/" rel="noopener noreferrer"&gt;Thoughtworks Go&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To get to know more about this topic you can read this &lt;a href="https://thenewstack.io/understanding-the-difference-between-ci-and-cd/" rel="noopener noreferrer"&gt;article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As this article will be huge, I will explain everything here in a series of the blogs where we will be configuring Jenkins in Windows and Ubuntu Operating Systems and create pipelines for Spring Boot and Angular Apps or maybe for React if you guys are interested.&lt;/p&gt;

&lt;p&gt;We will discuss the whole process from scratch and discuss each step in detail so you will have a clear picture of the process.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;That’s all folks!&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Thanks to &lt;a href="https://www.linkedin.com/in/mohan-nallapaneni/" rel="noopener noreferrer"&gt;Mohana Krishna&lt;/a&gt; for the feedback.&lt;/p&gt;

&lt;p&gt;I hope this article helped you with an overview of CI/CD Pipeline.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next article.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Follow me on &lt;a href="https://medium.com/@tech_sam" rel="noopener noreferrer"&gt;Medium&lt;/a&gt; and &lt;a href="https://dev.to/tech_sam"&gt;Dev.to&lt;/a&gt; to get an update about tech.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>cdcipipeline</category>
      <category>jenkins</category>
      <category>springboot</category>
      <category>angular</category>
    </item>
    <item>
      <title>Spring Boot with Redis conversion service and custom key converter</title>
      <dc:creator>Sumit</dc:creator>
      <pubDate>Fri, 05 Apr 2019 02:34:58 +0000</pubDate>
      <link>https://dev.to/tech_sam/spring-boot-with-redis-conversion-service-and-custom-key-converter-5fk9</link>
      <guid>https://dev.to/tech_sam/spring-boot-with-redis-conversion-service-and-custom-key-converter-5fk9</guid>
      <description>&lt;p&gt;This article is all about Spring-boot and Redis integration with using spring-data-redis.Spring Data Redis is the abstractions of the Spring Data platform to &lt;a href="https://redis.io/"&gt;Redis&lt;/a&gt; the popular in-memory data structure store. The full source code for this project is available on &lt;a href="https://github.com/Earth-43/Spring-Boot-Redis-ConversionServive"&gt;GitHub&lt;/a&gt;. Let’s straight come to the point.&lt;/p&gt;

&lt;p&gt;I am assuming that you are already familiar with spring boot and redis and you have chosen redis as a cache store for your project.&lt;/p&gt;

&lt;p&gt;In some scenarios where we have to deal with multitenant application or we want to cache multiple user data in Redis, then to avoid data conflicts and for better app arcitecture we can take advantage of spring redis data conversion service.&lt;/p&gt;

&lt;p&gt;Below logic is fine when we have to save the data which is common across all the users.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String cacheKey = “user-data”; 
   Cache cache = cacheManager.getCache(cacheKey);
   Cache.ValueWrapper result = cache != null ? cache.get(cacheKey) : null;
   if(result.get()!=null){
        // get the data and proceed 
    }else{
        cache.put(cacheKey, userData);
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But what if when you want to save individual user data then the above logic will not work. Then we can use conversion service with a custom key converter which allows us to add a dynamic prefix to user data like user id.&lt;/p&gt;

&lt;h3&gt;
  
  
  # Steps to integrate spring data redis
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;add following dependencies into your build.gradle file or if it is maven then in pom.xml
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;compile group: ‘org.springframework.data’, name: ‘spring-data-redis’, version: ‘2.1.5.RELEASE’&lt;br&gt;
 compile group: ‘org.apache.commons’, name: ‘commons-pool2’, version: ‘2.0’&lt;br&gt;
 compile group: ‘redis.clients’, name: ‘jedis’, version: ‘2.9.3’&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a custom key and converter class like.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; @AllArgsConstructor
 public class UserCacheKey {
 private String key;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;@Getter and @AllArgsConstructor annotations are part of Lombok project which we can cover in some other article. If you are not aware of Lombok then add default setter getter methods and constructor with a key argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; public class UserCacheKeyConverter implements Converter&amp;lt;UserCacheKey, String&amp;gt; {
  private UserServive userService;
  public UserCacheKeyConverter(UserServive userService) {
   this.userService = userService;
 }
 @Nullable
 @Override
 public String convert(UserCacheKey userCacheKey) {
 String userId = userService.getUserId(userCacheKey);
 return String.format(“%s_%s”, userId , userCacheKey.getKey());
 }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a Redis configuration file.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Bean(name = “userCacheManager”)
 public RedisCacheManager userCacheManager(RedisConnectionFactory 
 connectionFactory, UserService userService) {
 RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
 DefaultFormattingConversionService conversionService = (DefaultFormattingConversionService) redisCacheConfiguration.getConversionService();
 conversionService.addConverter(UserCacheKey.class, String.class, new UserCacheKeyConverter(userService));
 redisCacheConfiguration
 .entryTtl(Duration.ofSeconds(1800)).withConversionService(conversionService)
 .disableCachingNullValues();
 return RedisCacheManager.builder(connectionFactory)
 .cacheDefaults(redisCacheConfiguration)
 .withInitialCacheConfigurations(Collections.singletonMap(“user-cache”, redisCacheConfiguration))
 .build();
 }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;so here we are creating a RedisCacheManager which will handle only user cache related operations. Anywhere we can inject this RedisCacheManager as a named bean userCacheManager (@Qualifier(userCacheManager)) and perform the relevant operations like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cache cache = userCacheManager.getCache(“user-cache”);
 UserCacheKey cacheKey = new UserCacheKey(“some-user-data”);
 Cache.ValueWrapper result = cache != null ? cache.get(cacheKey) : null;
 if(result.get()!=null){
 // get the data and proceed 
 }else{
 cache.put(cacheKey, userData);
 }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So whenever you will call cache.get method first it will call cache converter and convert the key. It will help us to abstract the cache logic and reduce complexity.&lt;/p&gt;

&lt;p&gt;If you found this helpful or would like to chat about anything related to web or mobile development; drop a comment below. I’d love to discuss. Stay tuned for more content.&lt;/p&gt;

</description>
      <category>java</category>
      <category>springboot</category>
      <category>redis</category>
      <category>caching</category>
    </item>
    <item>
      <title>Clash Of ClassLoaders</title>
      <dc:creator>Sumit</dc:creator>
      <pubDate>Sun, 03 Mar 2019 05:56:36 +0000</pubDate>
      <link>https://dev.to/tech_sam/clash-of-classloaders-4l0p</link>
      <guid>https://dev.to/tech_sam/clash-of-classloaders-4l0p</guid>
      <description>&lt;p&gt;In the world of code sometimes situations are like you are trying to build a Burj Khalifa but stuck at first basement only recently I came across with a similar situation where I was working on an OAuth project where I was dealing with all complex security-related stuff and assuming that soon I will inaugurate my Burj Khalifa but I was stuck between Clash of ClassLoaders .&lt;/p&gt;

&lt;p&gt;In this article, I will explain about spring boot and apache ignite integration and how spring will override default java class loaders.&lt;br&gt;
you can find spring-boot ignite implementation code on &lt;a href="https://github.com/Earth-43/spring-boot-ignite"&gt;GitHub&lt;/a&gt;&lt;br&gt;
I was caching one of the user object and its properties like roles in ignite cache as an object, so at the time of retrieval I am getting an exception like&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;java.lang.IllegalStateException: Cached value is not of required type [cacheName=boot_ignite_cache, key=user_data, val=com.boot.ignite.bootignite.dto.User@1ae2cec9, requiredType=class com.boot.ignite.bootignite.dto.User]&lt;br&gt;
 at org.apache.ignite.cache.spring.SpringCache.get(SpringCache.java:77) ~[ignite-spring-2.7.0.jar:2.7.0]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;After spending ample amount of time I realized there is something serious problem and I have forgotten my basics and started reading about classloaders and soon I diagnosed the problem that spring is way more friendly then we thought . Spring is using something called restart classloaders The restart technology provided by Spring Boot works by using two classloaders.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Classes that do not change (for example, those from third-party jars) are loaded     into a base classloader.Classes that you are actively developing are loaded into a restart classloader . When the application is restarted, the restart classloader is thrown away and a new one is created. This approach means that application restarts are typically much faster than “cold starts”, since the base classloader is already available and populated.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So my &lt;strong&gt;user object&lt;/strong&gt; loaded by spring boot &lt;strong&gt;restart class loader&lt;/strong&gt; and ignite object is loaded by &lt;strong&gt;default class loader&lt;/strong&gt; both the class are different. &lt;br&gt;
The solution is either not to use &lt;a href="https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html"&gt;spring dev tools&lt;/a&gt; which nobody wants or either create a &lt;strong&gt;spring-devtools.properties&lt;/strong&gt; file and exclude the classes.&lt;/p&gt;

&lt;p&gt;Thanks for reading !!!  Keep growing Keep Going !!!&lt;/p&gt;

</description>
      <category>apacheignite</category>
      <category>springboot</category>
      <category>classloaders</category>
      <category>firstpost</category>
    </item>
  </channel>
</rss>
