<?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: vikash-agrawal</title>
    <description>The latest articles on Forem by vikash-agrawal (@vikashagrawal).</description>
    <link>https://forem.com/vikashagrawal</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%2F234593%2Fa2e5c05b-674d-44bf-927d-206037bd8027.png</url>
      <title>Forem: vikash-agrawal</title>
      <link>https://forem.com/vikashagrawal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/vikashagrawal"/>
    <language>en</language>
    <item>
      <title>Elastic Search</title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Tue, 03 Aug 2021 12:02:15 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/elastic-search-1ifd</link>
      <guid>https://forem.com/vikashagrawal/elastic-search-1ifd</guid>
      <description>&lt;h1&gt;
  
  
  What is Elastic Search
&lt;/h1&gt;

&lt;p&gt;Elastic Search is one of the most powerful search engine, which provides following functionality:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Full Text Search&lt;/li&gt;
&lt;li&gt;Analyze metric and performance data (APM: Application Performance Management)&lt;/li&gt;
&lt;li&gt;Receiving events from any of the application&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  How does Elastic Search work
&lt;/h1&gt;

&lt;p&gt;Elastic Search works with the document in the form of JSON, containing the list of fields and nested fields along with the corresponding values.&lt;br&gt;
Elastic Search enables the functionality over the REST API, with request response format.&lt;br&gt;
Elastic Search is written in java built on top of Apache Lucene.&lt;/p&gt;
&lt;h1&gt;
  
  
  Elastic Search Stack
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Elastic Search&lt;/li&gt;
&lt;li&gt;Kibana:

&lt;ul&gt;
&lt;li&gt;An analytic and Visualization Platform to monitor the performance of application, Elastic Search Cluster, &lt;/li&gt;
&lt;li&gt;Also provides platform for machine learning.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Log Stash

&lt;ul&gt;
&lt;li&gt;A data processing pipeline.&lt;/li&gt;
&lt;li&gt;The data received can be customer data, application logs from any kind of source like file, kafka, database etc.&lt;/li&gt;
&lt;li&gt;The data processed and shipped to any destination like kafka, elastic search.&lt;/li&gt;
&lt;li&gt;The Log stash goes through following:&lt;/li&gt;
&lt;li&gt;Input&lt;/li&gt;
&lt;li&gt;Filter&lt;/li&gt;
&lt;li&gt;Output&lt;/li&gt;
&lt;li&gt;Each of these steps is enabled through the plugins.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Beat: Light wight data shipper installed in the application server.

&lt;ul&gt;
&lt;li&gt;File Beat: Send the logs.&lt;/li&gt;
&lt;li&gt;Metric Beat: Collects and sends the application/service level metrics&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;X-Pack: Adds additional functionalities on top of Elastic Search and Kibana, like:

&lt;ul&gt;
&lt;li&gt;Authentication by integrating it with LDAP.&lt;/li&gt;
&lt;li&gt;Authorization&lt;/li&gt;
&lt;li&gt;Define alerts, trigger emails etc on performance monitoring.&lt;/li&gt;
&lt;li&gt;Machine learning e.g. Abnormality Detection, forecast future value etc.&lt;/li&gt;
&lt;li&gt;Elastic Search SQL, good to send SQL to ES over the http and JDBC.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  Installation
&lt;/h1&gt;
&lt;h3&gt;
  
  
  Mac
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Download the Elastic Search latest from the &lt;a href="https://www.elastic.co/downloads/elasticsearch"&gt;elasticsearch-download&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Download the Kibana through one of the following steps:

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.elastic.co/downloads/kibana"&gt;kibana-download&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Brew
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew tap elastic/tap
brew install elastic/tap/kibana-full
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;if you happen to see any error, follow the instructions as mentioned in the error message.&lt;br&gt;
e.g. if the error is due to xcode then&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;xcode-select --install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Post Installation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /_cat/nodes?v
GET /_cat/nodes?v=true&amp;amp;h=id,ip,port,v,m&amp;amp;pretty

# return just process
GET /_nodes/process?pretty
# same as above
GET /_nodes/_all/process?pretty
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Sharding and Scalability
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Elastic search data is stored in the index.&lt;/li&gt;
&lt;li&gt;Elastic Search Data in the given index is stored in the shards.&lt;/li&gt;
&lt;li&gt;1 TB of data can be stored in a cluster of more than one nodes with 500 GB hard disk capacity.&lt;/li&gt;
&lt;li&gt;Each shard is kind of independent index and actually an Apache Lucene Index.&lt;/li&gt;
&lt;li&gt;The size of the shard would increase based on the index size.&lt;/li&gt;
&lt;li&gt;It can store up to 2 Billion documents.&lt;/li&gt;
&lt;li&gt;It also helps in performance improvement if each of the queries are being executed in different shard and hence more than 1 shard for the given indes can reside in the same node.&lt;/li&gt;
&lt;li&gt;An index is created with 1 shard by default.&lt;/li&gt;
&lt;li&gt;Elastic Search less than 7.0.0 used to create index with 5 shards by default.&lt;/li&gt;
&lt;li&gt;During any of the queries, the shard is decided through:
&lt;strong&gt;value of _routing % number of shard&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Once the index is created, it's advisable not to change the number of shards as the existing documents wouldn't be fetched if query using the _routing parameters.&lt;/li&gt;
&lt;li&gt;To change the number of shards, use Elastic Search split API to increase the shards and Elastic Search Shrink API to decrease the shards, it internally performs the reindex operations.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;By default the routing is defined on the document id, which can be unpredictable on case the document id is randomly generated.&lt;/li&gt;
&lt;li&gt;Based on the use cases and to have the predictable behaviour, it's better to define the routing on any of the existing field.&lt;/li&gt;
&lt;li&gt;But the custom routing comes with more responsibility, e.g. 

&lt;ul&gt;
&lt;li&gt;if the value of the field on which the routing is defined, is changed then the reindexing is required to performed on the concerned document.&lt;/li&gt;
&lt;li&gt;GET search on document id, would need the routing also to passed otherwise the GET API might not return the results with the default routing.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Following factors should be considered to define number of shards:

&lt;ul&gt;
&lt;li&gt;Number of Nodes.&lt;/li&gt;
&lt;li&gt;Size of the index.&lt;/li&gt;
&lt;li&gt;Size of Hard disk in the node.&lt;/li&gt;
&lt;li&gt;Number of index&lt;/li&gt;
&lt;li&gt;Number of queries.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Replication
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Replication is created at the index level&lt;/li&gt;
&lt;li&gt;Replica works by coping the shards called replication shards.&lt;/li&gt;
&lt;li&gt;The original shard is called primary shard&lt;/li&gt;
&lt;li&gt;A primary shards and its replica shard is called &lt;strong&gt;replication group&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;An index is created with 1 replica by default.&lt;/li&gt;
&lt;li&gt;The replica shard will always be in the different nodes.&lt;/li&gt;
&lt;li&gt;In a cluster of one node, the status of any user index will be yellow.&lt;/li&gt;
&lt;li&gt;As soon as the new node is added the status would turn to green.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;There are following ways to add a new node to the cluster in local:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go inside the Elastic Search directory and execute:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt; bin/elasticsearch -Nnode.name=node-2 -Epath.data=./data/node-2 -Epath.logs=./logs/node-2
&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;Extract the elastic zip file to another directory, change the value of node in conf/elasticsearch.yml file and start the process.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Number of replica for kibana index is changed based on the number of nodes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Number of replica should depend upon many factors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It should be 2 for critical APIs else 1.&lt;/li&gt;
&lt;li&gt;Is the data stored in other DBs also?&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Query pointing to the same shard can be served by the replicas as well. Hence replication increase the availability and throughput of the query.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replicas is a recovery system in the given real time while snapshot is a recovery system in the given time&lt;br&gt;&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;GET /_cluster/health
GET /_cat/indices?v
PUT /product-index
GET /_cluster/health
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Node Roles
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Master:

&lt;ul&gt;
&lt;li&gt;node.master = true|false&lt;/li&gt;
&lt;li&gt;Responsible for creating and deleting indices, allotong shards/replicas to the node.&lt;/li&gt;
&lt;li&gt;This role is assigned to the node on rotation basis.&lt;/li&gt;
&lt;li&gt;In a big cluster, it make sense to declare one of the node as true.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Data Node

&lt;ul&gt;
&lt;li&gt;node.data = true|false&lt;/li&gt;
&lt;li&gt;This is enabled for all nodes by default.&lt;/li&gt;
&lt;li&gt;If you have the dedicated master node, then don't make it as data node.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Ingest

&lt;ul&gt;
&lt;li&gt;node.ingest = true|false&lt;/li&gt;
&lt;li&gt;Series of steps to perform some steps while ingesting the data, mainly used for log stash.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Machine Learning

&lt;ul&gt;
&lt;li&gt;node.ml: true|false&lt;/li&gt;
&lt;li&gt;This lets the machine learning related jobs.&lt;/li&gt;
&lt;li&gt;xpack.ml.enabled = true|false&lt;/li&gt;
&lt;li&gt;This enables the Machine learning APIs&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Coordinations

&lt;ul&gt;
&lt;li&gt;Enabled by disabling all other node roles.&lt;/li&gt;
&lt;li&gt;This lets the coordinations related job like shards selection and aggregations.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Index
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Create the Index
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PUT /product-index
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It supports many settings to define the number of shards, replicas etc.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the document to index
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST /product-index/_doc
{
  "product":"Dove Soap",
  "reviewsCount": 100,
  "price": 120
}
POST /product-index/_doc/100
{
  "product":"Dove Cream",
  "reviewsCount": 110,
  "price": 150
}
PUT /product-index/_doc/110
{
  "product":"Dove Cream",
  "reviewsCount": 120,
  "price": 150
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Analyze the value of &lt;em&gt;shards.total, it should be equal to 1 + no of replicas, 1 stands for primary shard as the data would go to only 1 primary shard and would get replicated in all replica shards in the __replication group&lt;/em&gt;_&lt;br&gt;
Document can be added using POST and PUT both with only difference is PUT defines that the document to be added on the mentioned URI hence id is mandatory field for PUT.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieve the documents by id
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  GET /product-index/_doc/100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Update the document

&lt;ul&gt;
&lt;li&gt;All the documents in the ES are immutable means the documents can not be changed.&lt;/li&gt;
&lt;li&gt;The update query retrieves the document and updates the fields and reindex the document with the same id. So it replaces the existing document not updates the document.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  POST /product-index/_update/100
{
  "doc": {"reviewsCount": 99, "inStock":120}

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Scripted updates

&lt;ul&gt;
&lt;li&gt;"ctx.op = 'noop'" will not cause any updates hence there is no change in the primary term and sequence number.&lt;/li&gt;
&lt;li&gt;Otherwise the response would say updates with the change in the primary term and sequence number regardless of the condition is met or not.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  POST /product-index/_update/100
{
  "script" : {
    "source": "ctx._source.price++"
  }
}

POST /product-index/_update/100
{
  "script" : {
    "source": "ctx._source.price = 500"
  }
}

POST /product-index/_update/100
{
  "script" : {
    "source": """
    if(ctx._source.price &amp;gt; 100){
      ctx.op = 'noop';
    }
    ctx._source.price = 150
    """
  }
}

POST /product-index/_update/100
{
  "script" : {
    "source": """
    if(ctx._source.price &amp;lt; 100){
      ctx._source.price = 150;
    }
    """
  }
}

POST /product-index/_update/100
{
  "script" : {
    "source": """
    if(ctx._source.price &amp;gt; 100){
      ctx.op = 'delete';
    }
    ctx._source.price = 150
    """
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Upserts

&lt;ul&gt;
&lt;li&gt;If the document doesn't exist, it would index the new document.&lt;/li&gt;
&lt;li&gt;If the document exists, it would execute the script (make the updates)
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#upserts
GET /product-index/_doc/101
POST /product-index/_update/101
{
  "script": {"source": "ctx._source.reviewsCount++"},
  "upsert": {
    "product":"Dove Soap",
    "reviewsCount": 125,
    "price": 123
  }
}
GET /product-index/_doc/101
POST /product-index/_update/101
{
  "script": {"source": "ctx._source.reviewsCount++"},
  "upsert": {
    "product":"Dove Soap",
    "reviewsCount": 125,
    "price": 123
  }
}
GET /product-index/_doc/101
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Replace the Document
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Add the document to the index
PUT /product-index/_doc/101
{
  "product":"Dove Soap",
  "reviewsCount": 100,
  "price": 120
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Delete the document
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DELETE /product-index/_doc/101
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Journey to Cloud Migration</title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Fri, 25 Sep 2020 13:43:18 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/journey-to-cloud-migration-3nmm</link>
      <guid>https://forem.com/vikashagrawal/journey-to-cloud-migration-3nmm</guid>
      <description>&lt;h1&gt;
  
  
  Background
&lt;/h1&gt;

&lt;p&gt;Lucky to be part of cloud migration team in my organization, with the best thing is my involvement when it matters most for me.&lt;/p&gt;

&lt;p&gt;I take this platform to share my learnings which I have learnt while talking to the people and exploring the solutions for the technical problem, which is eventually leading me to gain leadership and technical skills.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some of the learnings and takeaway:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Split the tasks into 2 categories:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Tasks, which are required to be completed at any cost.&lt;/li&gt;
&lt;li&gt;There is no end to improvement, so tasks, which qualify for continual improvement.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Phase wise migration
&lt;/h3&gt;

&lt;p&gt;Migration would occur in following 2 categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Application&lt;/li&gt;
&lt;li&gt;Data&lt;/li&gt;
&lt;li&gt;Infrastructure Services (Database, Messaging Platform)&lt;/li&gt;
&lt;li&gt;DevOps Pipelines&lt;/li&gt;
&lt;li&gt;Most importantly, Alerts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Migration would generate to lot of unpredictable behaviour, so it might led to give a thought to the following factors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Define phases in the context of traffic volume, it can a client or set of clients generating low traffic.&lt;/li&gt;
&lt;li&gt;Give thought to the delta data migration

&lt;ul&gt;
&lt;li&gt;Does the current infrastructure (database) supports delta data back up&lt;/li&gt;
&lt;li&gt;Proposed infrastructure support delta data restoration.`&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Nothing but the set up from the scratch
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;So it's worth investing in having the local set up where you can debug the application from your IDE in your development environment.&lt;/li&gt;
&lt;li&gt;It's a golden opportunity to upgrade all your existing services because of following reasons:

&lt;ul&gt;
&lt;li&gt;Need to conduct all the possible testings irrespective of service upgrade.`&lt;/li&gt;
&lt;li&gt;Uncertainty on how the new target system would behave with the services.`&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2P Dependencies
&lt;/h3&gt;

&lt;p&gt;Make sure you highlight the dependencies on the dependent team first otherwise you might end up in a situation where you are ready to Go Live but you need to complete last moment thing like traffic diversion. We had the similar scenario where we had to communicate the team to add header element in their request URL so that the traffic can be diverted to new infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistake, which you might make
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Make sure to confirm in your source code repository and deployment pipeline if all services have been migrated. We missed some of the services because of following reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One service was missed as we searched with some patterns and this particular service was not full filled by this pattern.&lt;/li&gt;
&lt;li&gt;Root cause: One of the Git repo contains another un related micro service.&lt;/li&gt;
&lt;li&gt;Learnings: Have the common pattern and hence get this un related micro service to another new git repo.&lt;/li&gt;
&lt;li&gt;Root cause: Git repos were scanned based on patterns and one of the git repo was not following this pattern.&lt;/li&gt;
&lt;li&gt;Learnings:

&lt;ul&gt;
&lt;li&gt;Scan should happen to all possible places, but not limited to just following:&lt;/li&gt;
&lt;li&gt;Git&lt;/li&gt;
&lt;li&gt;Container Repository&lt;/li&gt;
&lt;li&gt;Log Aggregator&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;One deployment was missed as this deployment was part of already migrated module.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don't ignore any single error message, which you see as part of testing, it can be functional testing or load testing. Because of the ignorance, we had to increase the meta space memory for the JVM from 128m to 160m post deployment.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What went well
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;After migration, there was traffic for delivery but not for ingestion. Upon highlight, the concerned team had to rectify their side.&lt;/li&gt;
&lt;li&gt;Load Test, which gives the proof for the microservice scalability and API performance, was on top priority.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Challenges
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;While using Azure VM, we realized that adding data disk from the portal is not sufficient. It's required to be changed on the kernel level.&lt;/li&gt;
&lt;li&gt;Upgrading the dependent infra (Database, messaging platform) client version directly is not sufficient as each of the springboot maps to specific infra version through dependencies module. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Learnings from the leaders
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;There is no end to the work so don't hesitate to give some relax time to the mates, if team member is tired, we can't achieve any turnaround result.&lt;/li&gt;
&lt;li&gt;Irrespective of your busy schedule, explain all the interesting facts and root cause of any issues to the team, which you have gone through.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Database
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Couchbase
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://dev.to/vikashagrawal/couchbase-database-migration-i5f"&gt;couchbase database migration&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Couchbase Database Migration</title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Sun, 20 Sep 2020 11:42:53 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/couchbase-database-migration-i5f</link>
      <guid>https://forem.com/vikashagrawal/couchbase-database-migration-i5f</guid>
      <description>&lt;h1&gt;
  
  
  Good Practices about the Couchbase
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Create admin level users with all permission.&lt;/li&gt;
&lt;li&gt;Create admin level users with just read permission, it might need if you want to collect some statistics about the couchbase.&lt;/li&gt;
&lt;li&gt;Create separate user for buckets or each of the bucket with limited privileges.&lt;/li&gt;
&lt;li&gt;Upgrading memory on the VM level is not sufficient, you need to change for each of the services in the setting present in Couchbase Console UI. Keep some memory in buffer in case if you want to run some agents like stats collector. &lt;/li&gt;
&lt;li&gt;As the query services uses the temporary directory to scan the result, so change it to point to path in data disk not in OS disk.&lt;/li&gt;
&lt;li&gt;Granting bucket level permission is not sufficient, you should grant all the permission for the bucket.&lt;/li&gt;
&lt;li&gt;Keep each of the services like data service, index service, query service, search service, analytic service in separate nodes. It would provide the fault tolerant incase any of the node or service crashes.&lt;/li&gt;
&lt;li&gt;Not sure on other database, but it doesn't support back up with query filter.&lt;/li&gt;
&lt;li&gt;Couchbase 5.X onwards, it supports the replica index where it's not required to define the same index in each of the nodes to provide high availability rather it can be achieved with replica index.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;We performed upgrade of Couchbase 5.X to 6.X&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Strategy for upgrade:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Collect the following possible data from the previous installation:

&lt;ul&gt;
&lt;li&gt;CPU Core Size for the entire cluster and for each of the services&lt;/li&gt;
&lt;li&gt;RAM for each of the nodes and services.&lt;/li&gt;
&lt;li&gt;Data Volume.&lt;/li&gt;
&lt;li&gt;Keep the specification for the VMs and Data Disks separate for each of the services as index node data disk capacity might be less than the data disk hard disk and query node doesn't use data disk significantly.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Licensing cost for Couchbase Enterprise edition is done on node level, so make sure to use the advanced node so that more than 1 service can be accommodated if required.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Challenges with Database migrations
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;No filter supports for cbbackup, we had to use the cbq script to take the query based on the timestamp and set of data.&lt;/li&gt;
&lt;li&gt;As the above step is not the back up actually, so we had to write the spring boot application to perform UPSERT.

&lt;ul&gt;
&lt;li&gt;USERT is suggested if no document in source database is updated post migration.&lt;/li&gt;
&lt;li&gt;Specific field update is suggested if there is updates on both the DB.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;The above steps worked will but with some difference in meta data but can be ignored as no difference was observed when and DB operations were performed from using SDK or Couchbase Query Editor:

&lt;ul&gt;
&lt;li&gt;Flag: 33554432(COUCHBASE_CFFMT_JSON) vs ‘0’(COUCHBASE_VAL_IS_STRING)&lt;/li&gt;
&lt;li&gt;rev, cas: value differs.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Advantages with Couchbase 6.0:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Better UI to manage the settings and view data.&lt;/li&gt;
&lt;li&gt;Backup and restore with various options: There are 2 options from CB 6.0 CE to back up and restore:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cbbackup and cbrestore&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backup:

&lt;ul&gt;
&lt;li&gt;/opt/couchbase/bin/cbbackup -m full &lt;a href="http://localhost:8091"&gt;http://localhost:8091&lt;/a&gt; /tmp/cb-bkp -u USER -p  (The first full backup)&lt;/li&gt;
&lt;li&gt;/opt/couchbase/bin/cbbackup -m diff &lt;a href="http://localhost:8091"&gt;http://localhost:8091&lt;/a&gt; /tmp/cb-bkp -u USER -p PASSWORD (The next incremental backup)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Restore

&lt;ul&gt;
&lt;li&gt;/opt/couchbase/bin/cbrestore /tmp/cb-bkp/2020-07-21T125200Z/2020-07-21T125200Z-full &lt;a href="http://localhost:8091"&gt;http://localhost:8091&lt;/a&gt; --u USER -p PASSWORD -x rehash=1&lt;/li&gt;
&lt;li&gt;/opt/couchbase/bin/cbrestore /tmp/cb-bkp/2020-07-21T125200Z/2020-07-21T125822Z-diff &lt;a href="http://localhost:8091"&gt;http://localhost:8091&lt;/a&gt; -u USER -p PASSWORD -x rehash=1&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Cons:

&lt;ul&gt;
&lt;li&gt;While restoring, we need to restore full and then all incremental in the order.&lt;/li&gt;
&lt;li&gt;Difficult to manage all incremental dirs over the longer time, only solution is have the scheduled full back and remove all previous incremental backup dirs.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cbbackupmgr (Preferred options)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Register archive (one time process):
/opt/couchbase/bin/cbbackupmgr config -a /tmp/cb-bkp-mgr -r cluster&lt;/li&gt;
&lt;li&gt;Back up
/opt/couchbase/bin/cbbackupmgr backup -a /tmp/cb-bkp-mgr -r cluster -c couchbase://localhost -u USER -p PASSWORD
First backup will be full and then next onwards would be incremental.&lt;/li&gt;
&lt;li&gt;Merge all backup present under /tmp/cb-bkp-mgr/cluster/ on the day of back up
/opt/couchbase/bin/cbbackupmgr merge -a /tmp/cb-bkp-mgr -r cluster --start 2020-07-21T13_43_19.471413454Z --end 2020-07-21T13_54_33.394966624Z&lt;/li&gt;
&lt;li&gt;Restore
/opt/couchbase/bin/cbbackupmgr restore -a /tmp/cb-bkp-mgr -r cluster -c couchbase://localhost -u USER -p PASSWORD&lt;/li&gt;
&lt;li&gt;Pros:

&lt;ul&gt;
&lt;li&gt;With the merge, we can merge all backups on the day of merge so that we will have only 1 dir.&lt;/li&gt;
&lt;li&gt;cbbackupmgr comes with lot of options, one of them is list to see all the backup directories.&lt;/li&gt;
&lt;li&gt;/opt/couchbase/bin/cbbackupmgr list -a /tmp/cb-bkp-mgr&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Learnings
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Give a thought to define bucket based on any category e.g. clients or set of clients.&lt;/li&gt;
&lt;li&gt;Give thought to generate the document id based on the clients or set of clients.&lt;/li&gt;
&lt;li&gt;Backup definition interval is business driven.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>couchbase</category>
      <category>database</category>
      <category>cloudmigration</category>
    </item>
    <item>
      <title>Multi Threading In Java</title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Thu, 26 Sep 2019 15:04:30 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/multi-threading-in-java-il</link>
      <guid>https://forem.com/vikashagrawal/multi-threading-in-java-il</guid>
      <description>&lt;h1&gt;
  
  
  Thread Lifecycle in java
&lt;/h1&gt;

&lt;p&gt;Once a thread completes its execution, it reaches to Dead state that means the given thread cannot be started again, means you can’t invoke start method more than once.&lt;br&gt;
The join() method waits for a thread to die. In other words, it causes the currently running threads to stop executing until the thread it joins with completes its task.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TestJoinMethod1&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;  
 &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;   
  &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++){&lt;/span&gt;  
   &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;  
    &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  
   &lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
   &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;  
  &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  
  &lt;span class="o"&gt;}&lt;/span&gt;  
 &lt;span class="o"&gt;}&lt;/span&gt;  

 &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;[]){&lt;/span&gt;  
  &lt;span class="nc"&gt;TestJoinMethod1&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TestJoinMethod1&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;  
  &lt;span class="nc"&gt;TestJoinMethod1&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TestJoinMethod1&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;  
  &lt;span class="nc"&gt;TestJoinMethod1&lt;/span&gt; &lt;span class="n"&gt;t3&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TestJoinMethod1&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;  
  &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;  
  &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;   
   &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;join&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;  
  &lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
  &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;   

 &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;  
 &lt;span class="n"&gt;t3&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;  
&lt;span class="o"&gt;}&lt;/span&gt;  
&lt;span class="o"&gt;}&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:1       2       3       4       5       1       1       2       2       3       3       4       4       5       5&lt;/p&gt;

&lt;p&gt;Main thread will wait for all the user threads to complete then will exit.&lt;br&gt;
If there are no user threads are running then daemon thread will also die.&lt;/p&gt;
&lt;h1&gt;
  
  
  ThreadPool
&lt;/h1&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TestThreadPool&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;  
     &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;  
        &lt;span class="nc"&gt;ExecutorService&lt;/span&gt; &lt;span class="n"&gt;executor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Executors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;newFixedThreadPool&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;//creating a pool of 5 threads  &lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;  
            &lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="n"&gt;worker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WorkerThread&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  
            &lt;span class="n"&gt;executor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;execute&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;//calling execute method of ExecutorService  &lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;  
        &lt;span class="n"&gt;executor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;shutdown&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;  
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(!&lt;/span&gt;&lt;span class="n"&gt;executor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isTerminated&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;   &lt;span class="o"&gt;}&lt;/span&gt;  

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Finished all threads"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  
    &lt;span class="o"&gt;}&lt;/span&gt;  
 &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pool-1-thread-1 (Start) message = 0
pool-1-thread-2 (Start) message = 1
pool-1-thread-3 (Start) message = 2
pool-1-thread-5 (Start) message = 4
pool-1-thread-4 (Start) message = 3
pool-1-thread-2 (End)
pool-1-thread-2 (Start) message = 5
pool-1-thread-1 (End)
pool-1-thread-1 (Start) message = 6
pool-1-thread-3 (End)
pool-1-thread-3 (Start) message = 7
pool-1-thread-4 (End)
pool-1-thread-4 (Start) message = 8
pool-1-thread-5 (End)
pool-1-thread-5 (Start) message = 9
pool-1-thread-2 (End)
pool-1-thread-1 (End)
pool-1-thread-4 (End)
pool-1-thread-3 (End)
pool-1-thread-5 (End)
Finished all threads
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Wait-notify
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;com.learnings.synch&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Tutorial&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Account&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Account&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;depositThreads&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
       &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;withdrawThreads&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;];&lt;/span&gt;
       &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="n"&gt;depositThreads&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UserThread&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"deposit"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
       &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="n"&gt;withdrawThreads&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;UserThread&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"withdraw"&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
       &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Thread&lt;/span&gt; &lt;span class="n"&gt;thread&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;withdrawThreads&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="n"&gt;thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
       &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;InterruptedException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;printStackTrace&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
       &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Thread&lt;/span&gt; &lt;span class="n"&gt;thread&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;depositThreads&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="n"&gt;thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;

   &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/**
*
*/&lt;/span&gt;
&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;com.learnings.synch&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
* @author Vikash Agrawal 
*
*/&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Account&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;lock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

   &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;withdraw&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;

   &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;deposit&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;

   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;getBalance&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;

   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;deposit&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="kd"&gt;synchronized&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Will be deposited by: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;currentThread&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
           &lt;span class="n"&gt;deposit&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           &lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;notify&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
           &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"After deposit: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;getBalance&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;

   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;withdraw&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="kd"&gt;synchronized&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Will be withdrawn by: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;currentThread&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
           &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;getBalance&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
               &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                   &lt;span class="n"&gt;lock&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;wait&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
               &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;InterruptedException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                   &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;printStackTrace&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
               &lt;span class="o"&gt;}&lt;/span&gt;
           &lt;span class="o"&gt;}&lt;/span&gt;
           &lt;span class="n"&gt;withdraw&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"After withdraw: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;getBalance&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/**
*
*/&lt;/span&gt;
&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;com.learnings.synch&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
* @author Vikash Agrawal 
*
*/&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserThread&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;operation&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Account&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;UserThread&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Account&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;operation&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
       &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;operation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;operation&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;

   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;operation&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"deposit"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
           &lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;deposit&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
           &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
       &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s"&gt;"withdraw"&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
           &lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;withdraw&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
           &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Java Updates</title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Thu, 26 Sep 2019 14:50:01 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/java-updates-5h0c</link>
      <guid>https://forem.com/vikashagrawal/java-updates-5h0c</guid>
      <description>&lt;h1&gt;
  
  
  Java 8 updates
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Functional Interface
&lt;/h2&gt;

&lt;p&gt;• An interface with just 1 abstract method is called Functional Interface.&lt;br&gt;
• A Functional Interface only can be used for lambda as there is no way of combining more than 1 method to the single instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lambda
&lt;/h2&gt;

&lt;p&gt;• It’s a way to override a method in a simpler way.&lt;br&gt;
• It can be single-statement without any curly braces.&lt;br&gt;
• It can be multiline enclosed in the curly braces.&lt;br&gt;
• Single statement outcome will be “return” value (No need of explicit return value)&lt;br&gt;
• Content of lambda can be extracted to a private method.&lt;br&gt;
• A lambda method can be with parameter or without parameters (in case of single parameter).&lt;/p&gt;

&lt;h2&gt;
  
  
  Default Method
&lt;/h2&gt;

&lt;p&gt;• Java 8 onwards allows to have method definition with keyword default in the interface.&lt;br&gt;
• 2 interfaces with same default method mandate the method to be overridden in the class implementing these 2 interfaces. (I’s the same reason that java doesn’t allow 2 classes to be extended.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Static method
&lt;/h2&gt;

&lt;p&gt;• Similar to static method in the given class, interface also allows to have the static method.&lt;br&gt;
• The static method in interface is the property of the interface. Means this method can be accessed using the interface only not by another interface extending this interface or class implementing this interface.&lt;/p&gt;

&lt;h2&gt;
  
  
  Foreach method
&lt;/h2&gt;

&lt;p&gt;• Iterable interface, a super interface of collection framework/interface, have the default method implementation of foreach method.&lt;br&gt;
• To iterate through the element in the collection framework, the traditional way of doing it is getting the iterator and iterate through each of the elements and then perform the business logic inside the for loop.&lt;br&gt;
• Foreach method will have the iteration logic within it, that means the client just needs to take care of business logic.&lt;br&gt;
• Other difference between this approach is, foreach method will use the internal iterator as compared to external iterator in traditional logic. And this external iterator has to be taken care with the ConcurrentModificationException.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>IPV4 vs IPV6</title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Thu, 26 Sep 2019 14:44:56 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/ipv4-vs-ipv6-3m0a</link>
      <guid>https://forem.com/vikashagrawal/ipv4-vs-ipv6-3m0a</guid>
      <description>&lt;h1&gt;
  
  
  IPV4:
&lt;/h1&gt;

&lt;p&gt;• It’s a decimal based IP address.&lt;br&gt;
• It contains 4 decimal number separated by dot.&lt;br&gt;
• Each number ranges from 0 to 255, that means 00000000 to 11111111.&lt;br&gt;
• Each of the decimal is 8 bits long, so it’s 32 bits IP address.&lt;/p&gt;

&lt;h1&gt;
  
  
  IPV6:
&lt;/h1&gt;

&lt;p&gt;• It's a hexadecimal based IP address.&lt;br&gt;
• It contains 8 hexadecimal number separated by colon.&lt;br&gt;
• Each number ranges from 0 to that means 0000 0000 0000 0000 to FFFF FFFF FFFF FFFF&lt;br&gt;
• Each of the hexa decimal is 16 bits long, so it’s 128 bits.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Distributed Memory Caching</title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Thu, 26 Sep 2019 14:43:16 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/distributed-memory-caching-33fd</link>
      <guid>https://forem.com/vikashagrawal/distributed-memory-caching-33fd</guid>
      <description>&lt;p&gt;There are 2 kinds of in memory data storage system available:&lt;/p&gt;

&lt;h1&gt;
  
  
  Redis
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Redis is a single threaded system.&lt;/li&gt;
&lt;li&gt;It can be scaled horizontally easily.&lt;/li&gt;
&lt;li&gt;Size of the key and value can go upto 512 MB each.&lt;/li&gt;
&lt;li&gt;Following 5 types of data types available:

&lt;ul&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Hash&lt;/li&gt;
&lt;li&gt;List&lt;/li&gt;
&lt;li&gt;Set&lt;/li&gt;
&lt;li&gt;Sorted Set&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Any kind of CRUD operations can be performed on a field level of the given data.

&lt;ul&gt;
&lt;li&gt;which means the application doesn't need to load the entire data.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;There are multiple eviction policy available:

&lt;ul&gt;
&lt;li&gt;No Eviction: On reaching the memory limit, it throws the error.&lt;/li&gt;
&lt;li&gt;All Keys LRU: Remove keys by least recently used.&lt;/li&gt;
&lt;li&gt;Volatile LRU: Remove keys, that have an expiration time set, by the least recently used first.&lt;/li&gt;
&lt;li&gt;All Keys Random: Remove keys randomly.&lt;/li&gt;
&lt;li&gt;Volatile Random: Remove keys, that have an expiration time set, randomly&lt;/li&gt;
&lt;li&gt;TTL: Remove keys, that have expired wrt time.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;There are 2 kind of back up supported:

&lt;ul&gt;
&lt;li&gt;RDB Snapshot: This snapshot happens periodically.&lt;/li&gt;
&lt;li&gt;AOF: Append only file is perform for every write operation. It can slow down the write operation but ensures the data availability.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Memcached
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Memcached is a multi threaded system.&lt;/li&gt;
&lt;li&gt;It can be scaled vertically easily.&lt;/li&gt;
&lt;li&gt;Size of the key can be upto 250B and value can be upto 1 MB.&lt;/li&gt;
&lt;li&gt;Horizontal scaling is possible through client side complex algorithm.&lt;/li&gt;
&lt;li&gt;It's just on String Data Type.&lt;/li&gt;
&lt;li&gt;Not possible to perform any operations on a field level of the given data.

&lt;ul&gt;
&lt;li&gt;which means the application needs to load the entire data.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;It works on LRU eviction policy only.
• It's a distributed memory cached object storage.
• It has 4 components:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o Client software: fetch the list of available servers.
o Server software: A logic to store and retrieve the value for the passed key.
o Expiry: Mechanism to remove the older contents based on the time expiry.
o Client based hashing algorithm: to fetch the corresponding server.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;• The cached data is stored in the RAM so when RAM runs out of memory, it does the clean up.&lt;br&gt;
• There is no fault tolerance means it doesn't share the data with other servers.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Design Principles </title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Thu, 26 Sep 2019 14:37:59 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/design-principles-4ajp</link>
      <guid>https://forem.com/vikashagrawal/design-principles-4ajp</guid>
      <description>&lt;h1&gt;
  
  
  SOLID
&lt;/h1&gt;

&lt;p&gt;• &lt;strong&gt;Single Responsibility Principle&lt;/strong&gt;: A class should be defined to have only one responsibility to avoid compiling and testing the totally dependent changes in case the class is mixed of many responsibilities. Logger and java Persistence API (JPA) are the ideal example for this.&lt;br&gt;
• &lt;strong&gt;Open/Closed Principle&lt;/strong&gt;: Open for extension and closed for modification. It mandates to have the interface defined so that any new implementations can be provided independently and plugged without modifying the existing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;VehicleCalculations&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;calculateValue&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Bike&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if there is a requirement to calculate the cost for another Vehicle type, say 'Cycle' then above method would required to be modified.&lt;br&gt;
But if the above class is modified in the following way, then any new vehicle type can be added independetly&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;calculateValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{...}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;calculateValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cycle&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;calculateValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getValue&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;• &lt;strong&gt;Liskov Substitution Principle&lt;/strong&gt;: With the interface-based implementations, you can override the method with parameter of the method being of sub class. Means the type of super class can be replaced with the object of child class.&lt;br&gt;
• &lt;strong&gt;Interface Segregation Principle&lt;/strong&gt;: it avoids implementing the unrequired method from the interface. e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;refuel&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;openDoors&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bike&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// Can be implemented&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{...}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{...}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;refuel&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{...}&lt;/span&gt;

    &lt;span class="c1"&gt;// Can not be implemented&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;openDoors&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{...}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead it mandates to have another interface inheriting the super interface and have this sub interface declared with specific method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;refuel&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;FourWheeler&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;openDoors&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bike&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{...}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;stop&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{...}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;refuel&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{...}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;• &lt;strong&gt;Dependency Inversion&lt;/strong&gt;: Dependency should be on abstractions (interfaces and abstract classes) instead of concrete implementations (classes). &lt;br&gt;
Consider the example below. We have a Car class that depends on the concrete Engine class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Engine&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Engine&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Engine&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{...}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code will work, for now, but what if we wanted to add another engine type, let’s say a diesel engine? This will require refactoring the Car class.&lt;br&gt;
However, we can solve this by introducing a layer of abstraction. Instead of Car depending directly on Engine, let’s add an interface:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;EngineInterface&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;EngineInterface&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Car&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;EngineInterface&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PetrolEngine&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;EngineInterface&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{...}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DieselEngine&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;EngineInterface&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{...}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  DRY
&lt;/h1&gt;

&lt;p&gt;Don't repeat yourself to avoid the duplication of the code so the maintainability becomes easy. It also helps to find the bugs.&lt;/p&gt;

&lt;h1&gt;
  
  
  REST
&lt;/h1&gt;

&lt;p&gt;• Uniform Interface: A resource in the system should have only one logical URI and that should provide a way to fetch related or additional data.&lt;br&gt;
• Client Server: This essentially means that client application and server application MUST be able to evolve separately without any dependency on each other.&lt;br&gt;
• Stateless: If client application needs to be a stateful application for the end user, where user logs in once and do other authorized operations thereafter, then each request from the client should contain all the information necessary to service the request – including authentication and authorization details.&lt;br&gt;
• Cacheable: Well-managed caching partially or completely eliminates some client-server interactions, further improving scalability and performance.&lt;br&gt;
• Layer: REST allows you to use a layered system architecture where you deploy the APIs on server A, and store data on server B and authenticate requests in Server C&lt;br&gt;
• Code on demand (optional): You are free to return executable code to support a part of your application e.g. clients may call your API to get a UI widget rendering code.&lt;/p&gt;

&lt;h1&gt;
  
  
  Microservice
&lt;/h1&gt;

&lt;p&gt;Domain Driven Design: Domain driven design along with related technical logic makes sure to have single responsibility microservice.&lt;br&gt;
Hide implementation detail: with so many microservices being part of the complete application hide the implementations of one microservice from other.&lt;br&gt;
Decentralized: With so many microservices around, it has the flexibility to have a different DB or different schema of the same DB with each of the microservice. With this DB migration becomes easier.&lt;br&gt;
Failure isolation: with one microservice being unavailable due to any reason being scalability or performance impact that particular functionality not the entire application.&lt;br&gt;
Continuous Deliver: With so many microservices being part of single application mandates to have the CI/CD pipeline so it requires to have collaboration between the developers and dev ops.&lt;/p&gt;

&lt;h1&gt;
  
  
  Best Practices
&lt;/h1&gt;

&lt;p&gt;• Encapsulate what changes: have all the methods and fields declared as private and then based on the need increase the accessibility, don't jump directly to public.&lt;br&gt;
• Favor Composition Over Inheritance: Composition allows changing the behavior of a class at runtime by setting property.&lt;br&gt;
• Programming for Interface Not Implementation: use interface type in variable, return type or argument of method.&lt;br&gt;
• Delegation Principle: Don't do all the stuff yourself. Like if you want any objects to be compared using equals or hashcode, the client doesn't do it, it's the class which does it.&lt;/p&gt;

</description>
      <category>java</category>
      <category>design</category>
      <category>oop</category>
    </item>
    <item>
      <title>Kafka</title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Wed, 25 Sep 2019 15:20:52 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/kafka-27i4</link>
      <guid>https://forem.com/vikashagrawal/kafka-27i4</guid>
      <description>&lt;p&gt;• There are 4 components of Kafka:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o Producer
o Consumer
o Broker: A broker is nothing but the server and a node, which manages the topic.
o Zookeeper: Zookeeper maintains the state of brokers, in case of any broker going down or coming up, it notifies the zookeeper and zookeeper informs to the producer and consumer so that producer and consumer are connected to live broker.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;• Topic is a classification for the message type let's say data type.&lt;br&gt;
• The given topic is splitter into many partitions.&lt;br&gt;
• And these partitions are replicated across more than 1 broker, if the number of brokers is more than 1.&lt;br&gt;
• For the given partitions, there will be only 1 lead node and rest will be the slave node.&lt;br&gt;
• Messages from the producer can go into any partitions and hence gets replicated.&lt;br&gt;
• If the messages are assigned with the key, then it ensures the message with the same key in the particular partitions.&lt;br&gt;
• In this way, it makes sure that messages are sequenced in the partitions.&lt;br&gt;
• Kafka client (producer/consumer) to Kafka data transfer happens through https which makes sure that data is encrypted using SSL certificate.&lt;br&gt;
• Use case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o Messaging: A messaging platform built in publisher-subscriber model.
o Website tracking: to get the real time report of user activity in the website.
o Log aggregation: To aggregate the logs from many services.
o Fault tolerance: Kafka platform enables the back up of the events along with regular synch up.
o Stream Processing: events coming from multiple services can be processed in real 
time and then can be transferred to other platform like storm for further processing.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;• Eamples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o Twitter uses it to take the post from the registered users to another registered 
user to repost and read and to unregistered user for read.
o LinkedIn uses it for online consumption along with offline analytics while being 
sorted in Hadoop.
o Netflix uses it for real time monitoring and event processing.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>API Gateway</title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Wed, 25 Sep 2019 15:11:48 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/api-gateway-1hjn</link>
      <guid>https://forem.com/vikashagrawal/api-gateway-1hjn</guid>
      <description>&lt;h1&gt;
  
  
  Proxy
&lt;/h1&gt;

&lt;p&gt;Proxy is a dedicated computer or software system running in the same computer or different computer acts as intermidiary between the requester of a website and the actual web server.&lt;br&gt;
Type of proxy:&lt;br&gt;
• Forward Proxy: it helps in connecting the user to the website.&lt;br&gt;
• Reverse Proxy: it is used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o To allow load balancing between the server.
o To stream internal content to its user. (SSO page)
o To block some particular website.
Nginx 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Load balancers:
&lt;/h1&gt;

&lt;p&gt;• With the many servers configured as upstreams, you can define proxy_pass to this upstreams.&lt;br&gt;
• There are multiple types of load balancers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o Round Robin: this is by default.
o least_conn: the one with the least client connection will be picked up.
o ip_hash: each of the client has some unique key, the first few characters of this key works as server chooser. It helps in speeding up the process.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;• To provide high availability load balancers, you can plug in external load balancer also.&lt;br&gt;
• Caching&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o Various cache related information like path, key, validity can be configured to improve the performance.
o User data is suggested not to be cached to avoid sharing one user data with other user.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  API Gateway
&lt;/h1&gt;

&lt;p&gt;It is used to manage the API, also referred as translator, which includes &lt;br&gt;
• combining more than 1 APIs into 1&lt;br&gt;
• combining responses from more than 1 API into 1&lt;br&gt;
• Providing the default data/message in case of error from any API invocation&lt;br&gt;
• Security management&lt;/p&gt;

</description>
    </item>
    <item>
      <title>REST vs SOAP</title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Wed, 25 Sep 2019 15:06:06 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/rest-vs-soap-47ei</link>
      <guid>https://forem.com/vikashagrawal/rest-vs-soap-47ei</guid>
      <description>&lt;p&gt;• REST (REpresentational State Transfer) is an architectural style while SOAP (Simple Object &lt;br&gt;
Access Protocol) is a protocol.&lt;br&gt;
• REST is all about simplicity, where it comes with the lighter data (JSON), although it &lt;br&gt;
supports other format as well, e.g. simple TEXT., HTML, XML etc, while SOAP is built within &lt;br&gt;
the envelop, where it contains data in XML.&lt;br&gt;
• REST comes with SSL security and https while SOAP comes with WS-Security as well.&lt;br&gt;
• SOAP has built in ACID compliance that’s why it makes it favorable choice when it comes &lt;br&gt;
to sensitive data e.g. financial data.&lt;br&gt;
• AS REST is lighter so it needs less bandwidth as compared to SOAP.&lt;br&gt;
• Data can be cached only in REST not in SOAP.&lt;br&gt;
• SOAP has strict communication contract.&lt;br&gt;
• REST uses URL and URI to access the API while SOAP uses service interface (WSDL file) to &lt;br&gt;
expose its functionality to client application.&lt;br&gt;
• If the service is required to maintain the state from one request to another then SOAP is &lt;br&gt;
preferred.&lt;br&gt;
• The WSDL file is a contract between the client and server. The content in this file has all &lt;br&gt;
the information about the services being exposed, which includes field name, field type. If &lt;br&gt;
there is any change to any parameter, it would have the huge impact on all the client side &lt;br&gt;
implementation.&lt;br&gt;
• Using wsimport, you can generate all the classes from wsdl file. Wsdl file is a xml file which &lt;br&gt;
contains the schema. It can be used to create data object including the Authentication &lt;br&gt;
detail and sent it over the network. The signature for the request is similar between rest &lt;br&gt;
based service and soap based service with only difference:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o SOAP Action
o Soapenv
o soapenv: Body
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;• Status Code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o 200: Request got executed successfully.
o 201: resource has been created successfully.
o 202: Accept, means the request has been accepted for execution asynchronously.
o 203: Non Authoritative information, means the content has been delivered from 
third party
o 400: Bad request because of syntax error.
o 401: Authentication is needed.
o 403: Authenticated but don't have enough access for the given request.
o 404: Resource not found
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Spring Boot</title>
      <dc:creator>vikash-agrawal</dc:creator>
      <pubDate>Wed, 25 Sep 2019 15:00:54 +0000</pubDate>
      <link>https://forem.com/vikashagrawal/spring-boot-4ehk</link>
      <guid>https://forem.com/vikashagrawal/spring-boot-4ehk</guid>
      <description>&lt;h1&gt;
  
  
  What benefits Spring Framework provides:
&lt;/h1&gt;

&lt;p&gt;• Dependency injection: it’s very critical to provide a loosely coupled application&lt;br&gt;
• Duplication/Plumbing Code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o   Spring JDBC
o   Spring MVC
o   Spring AOP
o   Spring ORM
o   Spring JMS
o   Spring Test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Pillars of a spring boot project:
&lt;/h1&gt;

&lt;p&gt;• Auto Configuration: When we use Spring MVC, we need to configure component scan, dispatcher servlet, a view resolver, web jars (for delivering static content) among other things.&lt;br&gt;
Spring Boot looks at&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o   Frameworks available on the CLASSPATH
o   Existing configuration for the application. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Based on these, Spring Boot provides basic configuration needed to configure the application with these frameworks.&lt;br&gt;
All auto configuration logic is implemented in spring-boot-autoconfigure.jar.&lt;br&gt;
As soon as we add Spring Boot Starter Web as a dependency in our project, Spring Boot Autoconfiguration sees that Spring MVC is on the classpath. It autoconfigures dispatcherServlet, a default error page and webjars.&lt;br&gt;
• Spring Boot Starter project&lt;br&gt;
All web application needs Spring MVC, Jackson Databind (for data binding), Hibernate-Validator (for server side validation using Java Validation API) and Log4j (for logging)along with compatible versions of all these frameworks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o   spring-boot-starter-web-services - SOAP Web Services
o   spring-boot-starter-web - Web &amp;amp; RESTful applications
o   spring-boot-starter-test - Unit testing and Integration Testing
o   spring-boot-starter-jdbc - Traditional JDBC
o   spring-boot-starter-hateoas - Add HATEOAS features to your services
o   spring-boot-starter-security - 
 Authentication and Authorization using Spring Security.
 Basic Authentication is the default.
 Using default security password, Default userid is user. Default password is printed in the server start up log.
o   spring-boot-starter-data-jpa - Spring Data JPA with Hibernate
o   spring-boot-starter-cache - Enabling Spring Framework’s caching support
o   spring-boot-starter-data-rest - Expose Simple REST Services using Spring Data REST
o   spring-boot-starter-actuator - To use advanced features like monitoring &amp;amp; tracing to your application out of the box
o   spring-boot-starter-undertow, spring-boot-starter-jetty, spring-boot-starter-tomcat - To pick your specific choice of Embedded Servlet Container
o   spring-boot-starter-logging - For Logging using logback
o   spring-boot-starter-log4j2 - Logging using Log4j2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;• Spring Boot Starter Parent&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;o   All Spring Boot projects typically use spring-boot-starter-parent as the parent in pom.xml.
o   Spring Boot Starter Parent defines spring-boot-dependencies as the parent pom. It inherits dependency management from spring-boot-dependencies. Details in the next section.
o   Parent Poms allow you to manage the following things for multiple child projects and modules:
 Configuration - Java Version and Other Properties
 Dependency Management - Version of dependencies
 Default Plugin Configuration
o   A few other settings related to encoding and source, target version are also set in the parent pom.
&amp;lt;java.version&amp;gt;1.6&amp;lt;/java.version&amp;gt;&amp;lt;resource.delimiter&amp;gt;@&amp;lt;/resource.delimiter&amp;gt; &amp;lt;!-- delimiter that doesn't clash with Spring ${} placeholders --&amp;gt;&amp;lt;project.build.sourceEncoding&amp;gt;UTF-8&amp;lt;/project.build.sourceEncoding&amp;gt;&amp;lt;project.reporting.outputEncoding&amp;gt;UTF-8&amp;lt;/project.reporting.outputEncoding&amp;gt;&amp;lt;maven.compiler.source&amp;gt;${java.version}&amp;lt;/maven.compiler.source&amp;gt;&amp;lt;maven.compiler.target&amp;gt;${java.version}&amp;lt;/maven.compiler.target&amp;gt;
o   Spring Boot Starter Parent inherit from spring-boot-dependencies, it shares all these characteristics as well.
&amp;lt;properties&amp;gt;&amp;lt;activemq.version&amp;gt;5.13.4&amp;lt;/activemq.version&amp;gt;...&amp;lt;ehcache.version&amp;gt;2.10.2.2.21&amp;lt;/ehcache.version&amp;gt;&amp;lt;ehcache3.version&amp;gt;3.1.1&amp;lt;/ehcache3.version&amp;gt;...&amp;lt;h2.version&amp;gt;1.4.192&amp;lt;/h2.version&amp;gt;&amp;lt;hamcrest.version&amp;gt;1.3&amp;lt;/hamcrest.version&amp;gt;&amp;lt;hazelcast.version&amp;gt;3.6.4&amp;lt;/hazelcast.version&amp;gt;&amp;lt;hibernate.version&amp;gt;5.0.9.Final&amp;lt;/hibernate.version&amp;gt;&amp;lt;hibernate-validator.version&amp;gt;5.2.4.Final&amp;lt;/hibernate-validator.version&amp;gt;&amp;lt;hikaricp.version&amp;gt;2.4.7&amp;lt;/hikaricp.version&amp;gt;&amp;lt;hikaricp-java6.version&amp;gt;2.3.13&amp;lt;/hikaricp-java6.version&amp;gt;&amp;lt;hornetq.version&amp;gt;2.4.7.Final&amp;lt;/hornetq.version&amp;gt;&amp;lt;hsqldb.version&amp;gt;2.3.3&amp;lt;/hsqldb.version&amp;gt;&amp;lt;htmlunit.version&amp;gt;2.21&amp;lt;/htmlunit.version&amp;gt;&amp;lt;httpasyncclient.version&amp;gt;4.1.2&amp;lt;/httpasyncclient.version&amp;gt;&amp;lt;httpclient.version&amp;gt;4.5.2&amp;lt;/httpclient.version&amp;gt;&amp;lt;httpcore.version&amp;gt;4.4.5&amp;lt;/httpcore.version&amp;gt;&amp;lt;infinispan.version&amp;gt;8.2.2.Final&amp;lt;/infinispan.version&amp;gt;&amp;lt;jackson.version&amp;gt;2.8.1&amp;lt;/jackson.version&amp;gt;....&amp;lt;jersey.version&amp;gt;2.23.1&amp;lt;/jersey.version&amp;gt;&amp;lt;jest.version&amp;gt;2.0.3&amp;lt;/jest.version&amp;gt;&amp;lt;jetty.version&amp;gt;9.3.11.v20160721&amp;lt;/jetty.version&amp;gt;&amp;lt;jetty-jsp.version&amp;gt;2.2.0.v201112011158&amp;lt;/jetty-jsp.version&amp;gt;&amp;lt;spring-security.version&amp;gt;4.1.1.RELEASE&amp;lt;/spring-security.version&amp;gt;&amp;lt;tomcat.version&amp;gt;8.5.4&amp;lt;/tomcat.version&amp;gt;&amp;lt;undertow.version&amp;gt;1.3.23.Final&amp;lt;/undertow.version&amp;gt;&amp;lt;velocity.version&amp;gt;1.7&amp;lt;/velocity.version&amp;gt;&amp;lt;velocity-tools.version&amp;gt;2.0&amp;lt;/velocity-tools.version&amp;gt;&amp;lt;webjars-hal-browser.version&amp;gt;9f96c74&amp;lt;/webjars-hal-browser.version&amp;gt;&amp;lt;webjars-locator.version&amp;gt;0.32&amp;lt;/webjars-locator.version&amp;gt;&amp;lt;wsdl4j.version&amp;gt;1.6.3&amp;lt;/wsdl4j.version&amp;gt;&amp;lt;xml-apis.version&amp;gt;1.4.01&amp;lt;/xml-apis.version&amp;gt;&amp;lt;/properties&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  What is REST?
&lt;/h1&gt;

&lt;p&gt;REST stands for REpresentational State Transfer. REST specifies a set of architectural constraints. Any service which satisfies these constraints is called RESTful Service.&lt;br&gt;
The five important constraints for RESTful Web Service are&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;• Client - Server: There should be a service producer and a service consumer.
• The interface (URL) is uniform and exposing resources.
• The service is stateless.
• The service results should be Cacheable. HTTP cache, for example.
• Service should assume a Layered architecture. Client should not assume direct connection to server - it might be getting info from a middle layer - cache.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Fault Tolerance
&lt;/h1&gt;

&lt;p&gt;When we build a microservices architecture, there are a large number of small microservices, and they all need to communicate with one another.&lt;br&gt;
Let’s say Microservice5 is down at some point of time. The solution to this problem is to have a fallback in case of failure of a microservice. This aspect of a microservice is called fault tolerance.&lt;br&gt;
A popular framework used to implement fault tolerance is Hystrix, a Netflix open source framework. Here is a code example of the same:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/fault-tolerance-example"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nd"&gt;@HystrixCommand&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fallbackMethod&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"fallbackRetrieveConfguration"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;LimitConfiguration&lt;/span&gt; &lt;span class="nf"&gt;retrieveConfiguration&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;RuntimeException&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Not Available"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;LimitConfiguration&lt;/span&gt; &lt;span class="nf"&gt;fallbackRetrieveConfiguration&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;LimitConfiguration&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;999&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, if retrieveConfiguration() fails, then fallbackRetrieveConfiguration is called, which returns a hardcoded LimitConfiguration instance:&lt;br&gt;
Difference between catching exception and Hystrix&lt;br&gt;
• Metrics and Dashboarding provided Out of the Box which can help you peek into your system and dependent connection&lt;br&gt;
• Implements BulkHead by using different Thread Pools&lt;br&gt;
• Lower maintenance cost&lt;br&gt;
• Health check ability. It provides a health check class which plugins with Health monitoring APIs&lt;br&gt;
• The main difference is that Hystrix opens the circuit (it is an analogy to electrical circuits) when it detects an error and does not invoke downstream services until sometime has elapsed. This behavior prevents an avalanche of errors in cascading. It is similar to a smart traffic light that turns red and doesn't let you pass because it knows that you are going to have an accident a little later. After a configurable time, the circuit is closed again. You can see 'Circuit opened / closed' at Hystrix dashboard:&lt;/p&gt;

&lt;h1&gt;
  
  
  load balancing algorithms
&lt;/h1&gt;

&lt;p&gt;Ribbon offers wide variety of client side load balancing algorithms to choose from.&lt;/p&gt;

&lt;h1&gt;
  
  
  naming server
&lt;/h1&gt;

&lt;p&gt;Eureka Naming server offers naming server to register all the microservices, which can be used to fetch the address of the registered microservices.&lt;/p&gt;

&lt;h1&gt;
  
  
  Auto scaling
&lt;/h1&gt;

&lt;p&gt;You can containerize each microservice using Docker and create an image.&lt;br&gt;
Kubernetes has the capability to manage containers. Kubernetes can be configured to auto scale based on the load. Kubernetes can identify the application instances, monitor their loads, and automatically scale up and down.&lt;/p&gt;

&lt;h1&gt;
  
  
  Centralized Logging
&lt;/h1&gt;

&lt;p&gt;Using Log Streams is one way to implement centralized logging. The common way to implement it is to stream microservice logs to a common queue. Distributed logging server listens to the queue and acts as log store. It provides search capabilities to search the trace.&lt;br&gt;
Popular Implementations&lt;br&gt;
Some of the popular implementations include&lt;br&gt;
• the ELK stack (Elastic Search, Logstash and Kibana) for Centralized Logging&lt;br&gt;
• Zipkin, Open Tracing API And Zaeger for Distributed Tracing&lt;/p&gt;

&lt;h1&gt;
  
  
  API Gateway
&lt;/h1&gt;

&lt;p&gt;In microservices, we route all requests - both internal and external - through API Gateways. We can implement all the common features like authentication, logging, auditing, and rate limiting in the API Gateway.&lt;br&gt;
For example, you may not want Microservice3 to be called more than 10 times by a particular client. You could do that as part of rate limiting in the API gateway.&lt;br&gt;
You can implement the common features across microservices in the API gateway. A popular API Gateway implementation is Zuul API Gateway.&lt;/p&gt;

&lt;h1&gt;
  
  
  Centralized Configuration
&lt;/h1&gt;

&lt;p&gt;Configuration for all microservices (for all environments) is stored at one place - a centralized configuration store.&lt;br&gt;
When a microservice needs its configuration, it provides an id at launch - a combination of microservice name and the environment.&lt;br&gt;
Spring Cloud Config Server is one of the popular implementations of a cloud config server&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
