<?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>Forem: Sandilya Karavadi</title>
    <description>The latest articles on Forem by Sandilya Karavadi (@sandy10247).</description>
    <link>https://forem.com/sandy10247</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%2F941422%2F44c91dac-e06d-4717-af1d-902cb2d6fd2c.jpg</url>
      <title>Forem: Sandilya Karavadi</title>
      <link>https://forem.com/sandy10247</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sandy10247"/>
    <language>en</language>
    <item>
      <title>Processing File concurrently using Goroutines</title>
      <dc:creator>Sandilya Karavadi</dc:creator>
      <pubDate>Wed, 25 Jun 2025 12:33:45 +0000</pubDate>
      <link>https://forem.com/sandy10247/processing-file-concurrently-with-using-goroutines-1pc0</link>
      <guid>https://forem.com/sandy10247/processing-file-concurrently-with-using-goroutines-1pc0</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How to Read File&lt;/li&gt;
&lt;li&gt;How to Process File (i.e Channel) Concurrently with Goroutines&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Reading a File
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Spin up a &lt;code&gt;goroutine&lt;/code&gt; to read data from file in chunks using
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scanner.Scan()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuxi588vh8zpj25rna67t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuxi588vh8zpj25rna67t.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Processing &lt;code&gt;Channel&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Spin Up &lt;code&gt;N&lt;/code&gt; &lt;code&gt;goroutine&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Each one will take a &lt;code&gt;Chunk&lt;/code&gt; from the &lt;code&gt;Channel&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Extract data from the &lt;code&gt;Chunk&lt;/code&gt; and execute &lt;code&gt;processFn&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func ProcessFile(file io.Reader, numWorkers int, chunkSize int, processFn func(data []byte)) 

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

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90l5kt7ikioerrpqbyis.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90l5kt7ikioerrpqbyis.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Github Repo for code&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Sandy10247" rel="noopener noreferrer"&gt;
        Sandy10247
      &lt;/a&gt; / &lt;a href="https://github.com/Sandy10247/go-process-file" rel="noopener noreferrer"&gt;
        go-process-file
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A Sample Repo, to demonstrate File Processing concurrently
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;go-process-file&lt;/h1&gt;

&lt;/div&gt;

&lt;p&gt;A Sample Repo, to demonstrate File Processing concurrently&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Execution&lt;/h2&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/Sandy10247/go-process-file/./go-process-file.png"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FSandy10247%2Fgo-process-file%2F.%2Fgo-process-file.png" alt="Execution Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Dev to Article&lt;/h2&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://dev.to/sandy10247/processing-file-concurrently-with-using-goroutines-26l6-temp-slug-2512408?preview=f0d260d400094b1286bb1cf700f1c7c14dd250b2b731666d2a91293d0252ff1a70faf64f7a6aac68f8d9a151cc3bc51507833eb1bc1d1b95089dc65e" rel="nofollow"&gt;Processing File concurrently with using Goroutines&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Sandy10247/go-process-file" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/Sandy10247/go-process-file" rel="noopener noreferrer"&gt;Github Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://albertcolom.com/posts/how-to-process-gigantic-files-in-golang-fast-and-memory-efficient" rel="noopener noreferrer"&gt;Inspired by&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
    </item>
    <item>
      <title>Circuit Breaker 🎛️ pattern with GO</title>
      <dc:creator>Sandilya Karavadi</dc:creator>
      <pubDate>Tue, 10 Dec 2024 16:17:30 +0000</pubDate>
      <link>https://forem.com/sandy10247/circuit-breaker-pattern-with-go-5b78</link>
      <guid>https://forem.com/sandy10247/circuit-breaker-pattern-with-go-5b78</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;As Einstein said "perpetual motion machines are impossible". &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Server ⚙️ can&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go down i.e Go Offline&lt;/li&gt;
&lt;li&gt;Constantly give &lt;code&gt;500&lt;/code&gt; i.e DBs they are hitting can go down&lt;/li&gt;
&lt;li&gt;N number of natural causes that can make a remote server useless.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since Client won't have any information of the Server state, it will keep on trying and all the requests are gonna be failing.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Circuit Breaker proxy for Client
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5pn79gvp7dwdu1qw4wj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc5pn79gvp7dwdu1qw4wj.png" alt="Image description" width="651" height="539"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Microsoft's proposed solution is a Simple State Machine which can exist in one of three states &lt;/p&gt;

&lt;h3&gt;
  
  
  Closed 🟢
&lt;/h3&gt;

&lt;p&gt;-- No issues, operations can go as is.&lt;/p&gt;

&lt;h3&gt;
  
  
  Open 🔴
&lt;/h3&gt;

&lt;p&gt;-- Machine (i.e Server) is not in a good state, block everything. &lt;/p&gt;

&lt;h3&gt;
  
  
  Half Open 🟡
&lt;/h3&gt;

&lt;p&gt;-- Testing fire, let one or more requestes to go through to check Machine state. &lt;br&gt;
-- if success flip the machine state to "closed" 🟢 &lt;br&gt;
--  else move it to "open 🔴"&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;we can go through a well thought out implementation for this in &lt;a href="https://github.com/sony/gobreaker" rel="noopener noreferrer"&gt;Sony Circuit Breaker&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Below is an example for it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Server
&lt;/h4&gt;


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

import (
    "log"
    "net/http"
    "os"
)

// ExampleServer is a test server to check the "CircuitBreaker" pattern
type ExampleServer struct {
    addr      string
    logger    *log.Logger
    isEnabled bool
}

// NewExampleServer creates the instance of our server
func NewExampleServer(addr string) *ExampleServer {
    return &amp;amp;ExampleServer{
        addr:      addr,
        logger:    log.New(os.Stdout, "Server\t", log.LstdFlags),
        isEnabled: true,
    }
}

// ListenAndServe starts listening on the address provided
// on creating the instance.
func (s *ExampleServer) ListenAndServe() error {
    // The main endpoint we will request to
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        if s.isEnabled {
            s.logger.Println("responded with OK")
            w.WriteHeader(http.StatusOK)
        } else {
            s.logger.Println("responded with Error")
            w.WriteHeader(http.StatusInternalServerError)
        }
    })

    // Toggle endpoint to switch on and off responses from the main one
    http.HandleFunc("/toggle", func(w http.ResponseWriter, r *http.Request) {
        s.isEnabled = !s.isEnabled
        s.logger.Println("toggled. Is enabled:", s.isEnabled)
        w.WriteHeader(http.StatusOK)
    })

    return http.ListenAndServe(s.addr, nil)
}


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

&lt;/div&gt;


&lt;p&gt;Server.go &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;struct "ExampleServer"
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type ExampleServer struct {
    addr      string
    logger    *log.Logger
    isEnabled bool
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;here "isEnabled" is the server's way of saying I am online / offline. &lt;/li&gt;
&lt;li&gt; when &lt;code&gt;false&lt;/code&gt; don't send me anything at all, cause I am gonna fail them regardless.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;ExampleServer&lt;/code&gt; servers two routes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/&lt;/code&gt; 
-- responds with 200&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/toggle&lt;/code&gt;
-- responds with 200
-- toggles "isEnabled" struct state.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  client.go
&lt;/h4&gt;


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

import (
    "errors"
    "net/http"
)

type NotificationClient interface {
    Send() error // We ignore all the arguments to simplify the demo
}

type SmsClient struct {
    baseUrl string
}

func NewSmsClient(baseUrl string) *SmsClient {
    return &amp;amp;SmsClient{
        baseUrl: baseUrl,
    }
}

func (s *SmsClient) Send() error {
    url := s.baseUrl + "/"
    resp, err := http.Get(url)
    if err != nil {
        return err
    }
    defer resp.Body.Close()
    if resp.StatusCode &amp;lt; 200 || resp.StatusCode &amp;gt;= 300 {
        return errors.New("bad response")
    }

    return nil
}

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

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;SmsClient&lt;/code&gt; struct has a method &lt;code&gt;Send&lt;/code&gt; just makes an Api hit to server, return &lt;code&gt;error&lt;/code&gt; when Api hit is not successfull.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func (s *SmsClient) Send() error {
    url := s.baseUrl + "/"
    resp, err := http.Get(url)
    if err != nil {
        return err
    }
    defer resp.Body.Close()
    if resp.StatusCode &amp;lt; 200 || resp.StatusCode &amp;gt;= 300 {
        return errors.New("bad response")
    }

    return nil
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  circuit_breaker.go
&lt;/h4&gt;


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

import (
    "log"
    "os"
    "time"

    "github.com/sony/gobreaker/v2"
)

type ClientCircuitBreakerProxy struct {
    client NotificationClient
    logger *log.Logger
    gb     *gobreaker.CircuitBreaker[any] // downloaded lib structure
}

// shouldBeSwitchedToOpen checks if the circuit breaker should
// switch to the Open state
func shouldBeSwitchedToOpen(counts gobreaker.Counts) bool {
    failureRatio := float64(counts.TotalFailures) / float64(counts.Requests)
    return counts.Requests &amp;gt;= 3 &amp;amp;&amp;amp; failureRatio &amp;gt;= 0.6
}

func NewClientCircuitBreakerProxy(client NotificationClient) *ClientCircuitBreakerProxy {
    logger := log.New(os.Stdout, "CB\t", log.LstdFlags)

    // We need circuit breaker configuration
    cfg := gobreaker.Settings{
        // When to flush counters int the Closed state
        Interval: 5 * time.Second,
        // Time to switch from Open to Half-open
        Timeout: 7 * time.Second,
        // Function with check when to switch from Closed to Open
        ReadyToTrip: shouldBeSwitchedToOpen,
        // set Max Request in Half Open state to 5
        MaxRequests: 5,
        // On State change Handler Fn
        OnStateChange: func(_ string, from gobreaker.State, to gobreaker.State) {
            // Handler for every state change. We'll use for debugging purpose
            logger.Println("state changed from", from.String(), "to", to.String())
        },
    }

    return &amp;amp;ClientCircuitBreakerProxy{
        client: client,
        logger: logger,
        gb:     gobreaker.NewCircuitBreaker[any](cfg),
    }
}

func (c *ClientCircuitBreakerProxy) Send() error {
    // We call the Execute method and wrap our client's call
    _, err := c.gb.Execute(func() (any, error) {
        err := c.client.Send()
        return nil, err
    })
    return err
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;struct &lt;code&gt;ClientCircuitBreakerProxy&lt;/code&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;holds &lt;code&gt;client&lt;/code&gt; which can house &lt;code&gt;SmsClient&lt;/code&gt; which we declared above. &lt;/li&gt;
&lt;li&gt;holds an instance for &lt;code&gt;CircuitBreaker&lt;/code&gt; the state machine which hold the implementation for "Circuit Breaker" pattern.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type ClientCircuitBreakerProxy struct {
    client NotificationClient
    logger *log.Logger
    gb     *gobreaker.CircuitBreaker[any] // downloaded lib structure
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In the implementation &lt;code&gt;NewClientCircuitBreakerProxy&lt;/code&gt; fn takes a &lt;code&gt;SmsClient&lt;/code&gt; as parameter and provides the inital values for &lt;code&gt;CircuitBreaker&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;    // We need circuit breaker configuration
    cfg := gobreaker.Settings{
        // When to flush counters int the Closed state
        Interval: 5 * time.Second,
        // Time to switch from Open to Half-open
        Timeout: 7 * time.Second,
        // Function with check when to switch from Closed to Open
        ReadyToTrip: shouldBeSwitchedToOpen,
        // set Max Request in Half Open state to 5
        MaxRequests: 5,
        // On State change Handler Fn
        OnStateChange: func(_ string, from gobreaker.State, to gobreaker.State) {
            // Handler for every state change. We'll use for debugging purpose
            logger.Println("state changed from", from.String(), "to", to.String())
        },
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;Send&lt;/code&gt; method in struct &lt;code&gt;ClientCircuitBreakerProxy&lt;/code&gt; is a wrapper to &lt;code&gt;client&lt;/code&gt;'s &lt;code&gt;Send&lt;/code&gt; method.&lt;/p&gt;
&lt;h2&gt;
  
  
  main.go
&lt;/h2&gt;


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

import (
    "log"
    "os"
    "time"
)

func main() {
    logger := log.New(os.Stdout, "Main\t", log.LstdFlags)
    server := NewExampleServer(":8080")

    go func() {
        _ = server.ListenAndServe()
    }()

    var client NotificationClient

    client = NewSmsClient("http://127.0.0.1:8080")

    client = NewClientCircuitBreakerProxy(client)

    for {
        err := client.Send()
        time.Sleep(1 * time.Second)
        if err != nil {
            logger.Println("caught an error", err)
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;create a logger with
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;logger := log.New(os.Stdout, "Main\t", log.LstdFlags)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;start the simple go server with an run it concurrently with &lt;code&gt;go routine&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server := NewExampleServer(":8080")

    go func() {
        _ = server.ListenAndServe()
    }()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt; Initiate the Client with
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    var client NotificationClient

    client = NewSmsClient("http://127.0.0.1:8080")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;wrap it with Circuit Breaker proxy
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    client = NewClientCircuitBreakerProxy(client)

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

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;run an infinity loop which makes API hits to out simple server
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    for {
        err := client.Send()
        time.Sleep(1 * time.Second)
        if err != nil {
            logger.Println("caught an error", err)
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;As the &lt;code&gt;Client&lt;/code&gt; makes the API hits in regular intervals to the &lt;code&gt;Server&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;till an API hit &lt;code&gt;/toggle&lt;/code&gt; Circuit will make the Circuit Breaker to be in &lt;code&gt;open&lt;/code&gt; 🟢&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Reference
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/he110/circuitbreaker-pattern-in-go-43cn"&gt;Circuit Breaker Pattern in GO&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Sandy10247" rel="noopener noreferrer"&gt;
        Sandy10247
      &lt;/a&gt; / &lt;a href="https://github.com/Sandy10247/go-breaker-example" rel="noopener noreferrer"&gt;
        go-breaker-example
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A Simple implementation of Circuit Breaker pattern.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;go-breaker-example&lt;/h1&gt;

&lt;/div&gt;

&lt;p&gt;A Simple implementation of Circuit Breaker pattern.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;execution&lt;/h2&gt;

&lt;/div&gt;

&lt;p&gt;&lt;code&gt;go run .&lt;/code&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;output&lt;/h2&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/bd769724c3662b828d0a1b8d0e6145e860bb545ac519c33b1352d59c066ccf34/68747470733a2f2f6465762d746f2d75706c6f6164732e73332e616d617a6f6e6177732e636f6d2f75706c6f6164732f61727469636c65732f3178756d773331687a697978676a33726b3278752e676966"&gt;&lt;img src="https://camo.githubusercontent.com/bd769724c3662b828d0a1b8d0e6145e860bb545ac519c33b1352d59c066ccf34/68747470733a2f2f6465762d746f2d75706c6f6164732e73332e616d617a6f6e6177732e636f6d2f75706c6f6164732f61727469636c65732f3178756d773331687a697978676a33726b3278752e676966" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Sandy10247/go-breaker-example" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>go</category>
      <category>designpatterns</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Why add Tailwind CSS Atomic Classes to project ❓</title>
      <dc:creator>Sandilya Karavadi</dc:creator>
      <pubDate>Mon, 09 Dec 2024 17:12:21 +0000</pubDate>
      <link>https://forem.com/sandy10247/why-add-tailwind-css-atomic-classes-to-project-4n8o</link>
      <guid>https://forem.com/sandy10247/why-add-tailwind-css-atomic-classes-to-project-4n8o</guid>
      <description>&lt;p&gt;Problem&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When projects with many UI developers, start to code components in their own way, each declaring their own custom css classes, as per need. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Traditional way
&lt;/h3&gt;

&lt;p&gt;When we consider a simple well know issue to center a "div" in a page, this is how we typically create a class, with all the necessary styling.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
    &amp;lt;div class="center-div"&amp;gt;
        Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sint distinctio ratione
        corporis maiores beatae quasi veritatis iste consequuntur provident reiciendis
        quos molestias, quia ipsam laborum earum voluptatum quo numquam qui?
    &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
export default {
    name: 'Playground'
};
&amp;lt;/script&amp;gt;

&amp;lt;style lang="scss" scoped&amp;gt;
.center-div {
    box-sizing: border-box;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    top: 50%;
    left: 40%;
    max-width: 500px;
    background-color: black;
    color: white;
}
&amp;lt;/style&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;output :- &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgiuxvhyaqeg4b339c9q4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgiuxvhyaqeg4b339c9q4.png" alt="Image description" width="800" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Pros :- &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Developers can add any styling for the classes as they please. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cons :- &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As project grows, there won't be any uniformed styling for the project. &lt;/li&gt;
&lt;li&gt;It becomes tedious to apply same styles for new modules, as develepoers need to apply them themselves. &lt;/li&gt;
&lt;li&gt;Developer intent is not clear, i.e class name is "center-div" but inner styling can be anything they desire. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tailwind philosophy
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Building complex components from a constrained set of primitive utilities.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;We need to break a component classes from group up with Atomic classes.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
    &amp;lt;div
        class="box-border absolute flex justify-items-center top-1-2 left-40-p fill-gray-alpha color-fill max-w-sm"
    &amp;gt;
        Lorem ipsum dolor sit amet consectetur, adipisicing elit. Sint distinctio ratione
        corporis maiores beatae quasi veritatis iste consequuntur provident reiciendis
        quos molestias, quia ipsam laborum earum voluptatum quo numquam qui?
    &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script&amp;gt;
export default {
    name: 'Playground'
};
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6zff8dm7a9xyp2xhuz7c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6zff8dm7a9xyp2xhuz7c.png" alt="Image description" width="800" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What Happened, where are the classes ⁉️&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As you can see from the code above we have used quite a few classes in our "div"&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;class="box-border absolute flex justify-items-center top-1-2 left-1-2 fill-gray-alpha color-fill max-w-sm"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Each class is registered in the global application scope, which goes like this
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.box-border {
    box-sizing: border-box;
}

.absolute {
    position: absolute;
}

.flex {
    display: flex;
}

.justify-items-center {
    justify-items: center;
}

.top-1-2 {
    top: 50%
}

.left-40-p {
    left: 40%;
}

.max-w-sm {
    max-width: 24rem; /* 384px */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Since all these classes are available in the global scope, any developer can use them freely. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pros&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduces CSS Bundle size significantly. &lt;/li&gt;
&lt;li&gt;Ensures component styling to be consistent across the team. &lt;/li&gt;
&lt;li&gt;Developers can rapidly prototype their ideas, with less effort on redoing the same style. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cons&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Learning curve, each developer needs to get familiar with classes that already existing. &lt;/li&gt;
&lt;li&gt;Project needs to keep proper documentation, when adding these Global declared classes for others to consume. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Vue JS Pitfalls
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;:deep() / ::v-deep&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;the bain 😓 of Vue JS css targeting.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Traditional Classes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Targeting and Applying styling for the classes is very easy
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
    ::v-deep .center-div {
        background-color: red;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Taiwind Classes
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Developers need to get very creative when targeting "div"
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
    ::v-deep :first-of-type {
        background-color: red;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to Introduce Tailwind CSS Classes into your Application
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Traditional way
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;we can easily install them with&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://tailwindcss.com/docs/installation" rel="noopener noreferrer"&gt;Tailwind Installation&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D tailwindcss
npx tailwindcss init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;but this will install (i.e register) a plethorah of all the classes, in the global scope. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Unconventional 🤨 way
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;when your Application already has an existing css library, it would be ideal to cherry pick, the classes we need and add them in one css file and register it globally in the App.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Say your Application only wants flexibility in flexbox styling&lt;br&gt;
-- Get a list of the classes you need from &lt;a href="https://tailwindcss.com/docs/flex" rel="noopener noreferrer"&gt;flex styles&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;cherry pick the classes you 🤞 assume 🤞 your application needs, and add them as per need. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;with this way we can keep the CSS bundle significanlty small, but the development team needs to have tight control over css they apply 🤟.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* FlexBox */
.flex {
    display: flex;
}

.flex-row {
    flex-direction: row;
}

.flex-row-reverse {
    flex-direction: row-reverse;
}

.flex-col {
    flex-direction: column;
}

.flex-col-reverse   {
    flex-direction: column-reverse;

}

.flex-wrap {
    flex-wrap: wrap;
}

.flex-nowrap {
    flex-wrap: nowrap;
}

.grow {
    flex-grow: 1;
}

.grow-0 {
    flex-grow: 0;
}

.shrink {
    flex-shrink: 1;
}
.shrink-0 {
    flex-shrink: 0;
}
.justify-normal {
    justify-content: normal;
}
.justify-start {
    justify-content: flex-start;
}
.justify-end {
    justify-content: flex-end;
}
.justify-center {
    justify-content: center;
}
.justify-between {
    justify-content: space-between;
}
.justify-around {
    justify-content: space-around;
}
.justify-evenly {
    justify-content: space-evenly;
}
.justify-stretch {
    justify-content: stretch;
}
.justify-items-start {
    justify-items: start;
}
.justify-items-end {
    justify-items: end;
}
.justify-items-center {
    justify-items: center;
}
.justify-items-stretch {
    justify-items: stretch;
}
.justify-self-auto {
    justify-self: auto;
}
.justify-self-start {
    justify-self: start;
}
.justify-self-end {
    justify-self: end;
}
.justify-self-center {
    justify-self: center;
}
.justify-self-stretch {
    justify-self: stretch
}
.content-noraml {
    align-content: normal;
}
.content-center {
    align-content: center;
}
.content-start {
    align-content: start;
}
.content-end {
    align-content: end;
}
.content-between {
    align-content: space-between;
}
.content-around {
    align-content: space-around;
}
.content-evenly {
    align-content: space-evenly;
}
.content-baseline {
    align-content: baseline;
}
.content-stretch {
    align-content: stretch;
}
.items-start {
    align-items: start;
}
.items-end {
    align-items: end;
}
.items-center {
    align-items: center;
}
.items-baseline {
    align-items: baseline;
}
.items-stretch {
    align-items: stretch;
}

// Align Self 
.self-auto {
    align-self: auto;
}

.self-start {
    align-self: flex-start;
}

.self-end {
    align-self: flex-end;
}

.self-center {
    align-self: center;
}

.self-stretch {
    align-self: stretch;
}

.self-baseline {
    align-self: baseline;
}

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

&lt;/div&gt;



&lt;p&gt;Conslusion&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using Atomic classes with Tailwind as reference can &lt;/li&gt;
&lt;li&gt;Reduce a Project's CSS footprint. &lt;/li&gt;
&lt;li&gt;Maintain Styling consistensy across the Application. &lt;/li&gt;
&lt;li&gt;Increases Developer speed, with rapid prototyping. 🔥&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>tailwindcss</category>
      <category>css</category>
    </item>
  </channel>
</rss>
