Friday, November 19, 2021

Moving Persistence layer to ES

If you are looking for faster reads and writes in the background Elastic search framework suits it best. You don't need to add any caching layer and the server side response time would  meet the SLA  ie. below the permissible response time.

What you need to do is:

1. Create an Index

II. and attach it to an alias. That's it and BOOM!!!

 Creating Index

{

  "settings": {

    "index": {

      "number_of_shards": "2",

      "number_of_replicas": "3"

    }

  },

  "mappings": {

    "tweets": {

      "dynamic": "false",

      "dynamic_templates": [

        {

          "no_index_template": {

            "match": "*",

            "mapping": {

              "index": "no",

              "include_in_all": false

            }

          }

        }

      ],

      "properties": {

        "documentId": {

          "type": "keyword",

          "index": false

        },

        "tweetId": {

          "type": "keyword",

          "index": true

        }...

      }

    }

  }

}

How to add aliases 

POST_aliases{

  "actions": [

    {

      "add": {

        "index": "user_tweets-<commit-id>",

        "alias": "user_tweets"

      }

    },

    {

      "remove": {

        "index": "user_tweets-<old_commit-id>",

        "alias": "user_tweets"

      }

    }

  ]

}


Designing Caching Layers to speed up Page Load Time

 

Go Through HAR report and identify the backend services consuming maximum time. Now  identify the bottlenecks and  explore how the response time can be minimised.

- Is there any caching happening in the backend Services?

-Is It possible to use some index based framework, elastic cache?

-Is Site front enabled for your various pages. If the content is too much and Site front is not copping up in the comparison has it been excluded for sitefront?

-Can the consumer cache the responses in some caching framework with certain TTL , For eg Memcache to store service endpoint as key and the response as value , ttl =1m.

Wednesday, November 17, 2021

Regex Cheat Sheet

1.  Matching a set of words :  Hello Brick, Brik data ,Brck -->. Bri?c?k.  


More:

^ 

Start                            

$

End                            


a?

one or more a                            


(?i)

case insensitive                        


a{3}

exactly 3 of  a                            


a{3,6}

between 3 and 6 of  a                            



(.*)(?i)(tech?i?e)(.*?) 

        tech, techi, techie, techie house, the techie house                          

\d    

Any digit, short for [0-9]

\D

A non-digit, short for [^0-9]

\s

A whitespace character, short for [ \t\n\x0b\r\f]

\S

A non-whitespace character, short for

\w

A word character, short for [a-zA-Z_0-9]

\W

A non-word character [^\w]

\S+

Several non-whitespace characters

\b   

Matches a word boundary where a word character is [a-zA-Z0-9_]                         


           

^\d{4}\sHELLO\s     

1234 HELLO some-other words

\S

A non-whitespace character, short for

\w

A word character, short for [a-zA-Z_0-9]

\W

A non-word character [^\w]

\S+

Several non-whitespace characters

\b   

Matches a word boundary where a word character is [a-zA-Z0-9_]                


Try out:  https://regex101.com/


Monday, November 8, 2021

HOW To design a Generic Architecture

 In Software it is very essential to craft a solution which caters to the all possible requirements. Thus it would be generic enough to be able to support new additions without any rewriting the framework.

Following are the methodologies developers can choose from based on the capabilities they are looking for:

  •  XML based configuration controlled.
  •  Annotation driven
  • Factory implementation
  • Abstract design
  • Java Reflection
  • Persisting Rules in DB 
  • Persisting Rules in Json format
  • Java Translation framework
  • Rule Engine
  • RabbitMQ Event driven soltion.

Wednesday, October 27, 2021

Annotation Driven Design

 

 

Annotations are useful to tell:

-Constraints or usage of an element: e.g. @Deprecated, @Override, or @NotNull

- The "nature" of an element, e.g. @Entity, @TestCase, @WebService

-The behavior of an element: @Statefull, @Transaction

-How to process the element: @Column, @XmlElement

Some of the examples where annotations are used in test classes are:

  • @Before/BeforeEach :  Run before each test
  • @BeforeClass/BeforeAll : execute it only once before running all tests using @BeforeClass.
  • @AfterClass : Tear down
  • @AfterEach: Run after each method

Monday, September 27, 2021

How equipped your application is with Alerting

 There are various ways , the application can notify a set of recipients based on the error catrgories.

  •  Spring email: configure logback xml
  • Sending via  java mail api 

Thursday, September 23, 2021

Retryable Programming

 Spring retry is one of the implementation in Retryable Programming.
Code snippet:
Foo foo = template.execute(new RetryCallback<Foo>() {
    public Foo doWithRetry(RetryContext context) {
        // business logic here
    },
  new RecoveryCallback<Foo>() {
    Foo recover(RetryContext context) throws Exception {
          // recover logic here
    }
});
When the retry attempt is exhausted, the RetryOperations kicks off and it passes the control to a different callback, called the RecoveryCallback.

@Retryable(value = { SomeServerException.class}, maxAttempts = 3, backoff = @Backoff(delay = 2000, maxDelay=5000))
public void doSomething( arg1){
}

  @Recover
    public void recover(SomeServerException e, arg1){

}

Note: I. @Retryable should be invoked from some other bean.
          II. The method doSomething and recover should be a public method.



Wednesday, September 22, 2021

Application Memory Optimisation

 An application must be set with enough memory to be able to function as per the SLA. It should not be under or over utilised.

Things to be considered while setting up memory :

-Review the static and cached objects.

-Apply chunking instead of many items together.

-Apply common thread pooling to control the load

-Use fault tolerant library link resilency4j, circuit breaker etc.

-Have cloudWatch alarm setup tuned with read/write usage.

Thursday, September 2, 2021

Shell Scripting Essentials

Redirect stderror to output

$ cat foo.txt > output.txt 2>&1  // 2 stderror, &1 std output

cat nopx.txt > outputx.txt 2>&1 

// since there is an error the error will get redirected to outputx.txt


Command chaining &&


ls -ltr && mvn test && mvn deploy


Git shell coloring

# Regular Colors

Black="\[\033[0;30m\]"        # Black

Red="\[\033[0;31m\]"          # Red

Green="\[\033[0;32m\]"        # Green

Yellow="\[\033[0;33m\]"       # Yellow

Blue="\[\033[0;34m\]"         # Blue

Purple="\[\033[0;35m\]"       # Purple

Cyan="\[\033[0;36m\]"         # Cyan

White="\[\033[0;37m\]"        # White

More: https://gist.github.com/vratiu/9780109

Sunday, August 29, 2021

Tomcat Cookbook

 #How to find process id of a running program on a given port

sudo lsof  -i:8080

sudo lsof  -i:443

Sunday, August 8, 2021

SSH Essentilas


Secure shell:  Connect Remote server using SSH protocol

-check existing key :ls -al ~/.ssh // It shows existing public and private key pair

Generating a new SSH key and adding it to the ssh-agent

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

ssh-add -K ~/.ssh/id_rsa

$ eval "$(ssh-agent -s)"

ssh-add -K /Users/you/.ssh/id_rsa

-Copy the public key at remote server location ( eg.bitbucket server).

-Private key is fully encrypted.

https://sbme-tutorials.github.io/2019/data-structures/notes/public_key.html

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

Adding DNS entry to be able to connect through host name

ssh-keygen -R host_name