Common Design Patterns Overview

In this article, we’ll go through the overview of basic design patterns.

Circuit Breaker: This is a pattern that helps to manage calls from one service to another. There are three states of it:

  • Open: Calls from one service to another service are not allowed.
  • Closed: Calls from one service to another service are allowed.
  • Half-Open: A few calls from one service to another service are allowed but not all calls are allowed.

Two implementations for circuit breakers: Hystrix and Resilience4J.

Bulkhead: It allows to set maximum concurrent users that can connect to a service.

Backpressure: We will add details of it later.

Bloom filters: it is a data structure to search an element in a data set quickly with the level of certainty. Guava is a known Java API implementation of bloom filters.

HyperLogLog: it is a data structure that can provide the probabilistic calculation of the cardinality of a data set. Let’s say we want to understand how many unique visitors visited a mall. We can use HyperLogLog data structure to do it efficiently.

Gang of Four Design Patterns: It consists of three types of patterns: structural, creational, and behavioral, In total there are 23 of patterns.

References:

Bloom filters: https://richardstartin.github.io/posts/building-a-bloom-filter-from-scratch

HyperLogLog: https://www.baeldung.com/java-hyperloglog

Common Java libraries

Lombok API: This is a very helpful library that allows reducing infrastructural code. If we use Lombok API, we don’t have to write the code for getters, setters, constructor, equals, hash code methods, and even more.

Resilience4j API: It is a library designed for functional programming. One example use case is the rate limiter functionality, to limit number of maximum requests served by an API in a defined time period. Other examples are:

  • Concurrency control using bulkhead module
  • Fault Tolerant using retry

Hystrix API: Hystrix API can help make a service fault tolerant and resilient.

Javatuples: It’s an API that allows us to work with tuples. A tuple is a sequence of unrelated objects of different types. For example, a tuple may contain an integer, a string, and an object.

Javasist, CGLib, and ASM: These are APIs to manipulate Java byte codes.

P6Spy: It is a library that allows logging of database operations in the realtime.

Java Transaction Management: A transaction is a series of actions that must be completed. Java provides multiple ways to control transactions. Java provides transactions that are based on JDBC, JPA, JMS, Global Transactions, Java Transaction API (JTA), Java Transaction Service (JTS), and other related ways.

References:

Strength app part 5: Enable https on AWS

This is the part 5 of application development series. Refer to part 4 for the previous information. On our strength application, we wanted to enable https certificate. As it is for learning purpose, we wanted to keep it low cost.

Here were our options:

  • Enable AWS provided https option.
  • Get a free https certificate via letsencrypt and enable it on AWS. For our Sprint Boot application, we needed to generate a keystore.p12 file. We decided to opt for option2: get a free https certificate via letsencrypt website.

Our next challenge is to access the generated certificate into Spring Boot application in a way that is scalable in the future and does not go away if we terminate our EC2 instance on the ECS cluster. Here are options for us:

  • Manually copy https certificate to EC2 instance. We did not opt for this option. Reason is, if we terminate our ECS instance (attached to the ECS cluster), the https certificate will be deleted with the termination of the EC2 instance.
  • Keep the certificate at Amazon S3. Then, copy it to EC2 instance manually. We did not opt this option because every time we have a need to recreate an EC2 instance, we will have to manually copy the certificate.
  • When creating an EC2 instance within ECS cluster, add commands in user data option, to copy the certificate from AWS S3. We think this is an optimum option. But we couldn’t enable it. Free version of ECS enabled EC2 instance did not allow adding user data properly. To allow running user data into EC2 instance, we had to run an EC2 agent configuration. Running these configurations were either not easily available or too complicated within the free tier EC2 instance. So, we did not opt this option.
  • Add the https certificate within the Spring Boot application via S3 copy using SSL configuration. This could have been a considerable option. Within Spring Boot code, we can add SSL configuration bean to copy the certificate from AWS S3 and recreate a certificate file within the Spring Boot application. Below is a sample code to do it:

import java.io.File;

import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class SslConfiguration {

@Bean
public ServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(redirectConnector());
    return tomcat;
}

private Connector redirectConnector() {

    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");

    connector.setPort(8443);
    connector.setSecure(true);
    connector.setScheme("https");
    connector.setAttribute("keyAlias", "tomcat");
	connector.setAttribute("keystorePass", "<hidden>");
	connector.setAttribute("keyStoreType", "PKCS12");

    Object keystoreFile;
    File file = new File("");// ADD PATH
    String absoluteKeystoreFile = file.getAbsolutePath();

    connector.setAttribute("keystoreFile", absoluteKeystoreFile);
    connector.setAttribute("clientAuth", "false");
    connector.setAttribute("sslProtocol", "TLS");
    connector.setAttribute("SSLEnabled", true);
    return connector;

}

}


  • Add the https certificate within the Spring Boot application via S3 using properties file. To use this option, we need to read the https certificate file from application.properties. Below is a sample code to do it:

private static void copySSLCertificateFromS3() {

try {

Properties props = readPropertiesFile("src/main/resources/application.properties");

String clientRegion = props.getProperty("clientRegion");

String bucketName = props.getProperty("bucketName");

String sslFileNameWithPath = props.getProperty("sslFileNameWithPath");

String keyStoreFileName = props.getProperty("server.ssl.key-store");

AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(clientRegion)

.withCredentials(new ProfileCredentialsProvider()).build();

S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, sslFileNameWithPath));

InputStream objectData = object.getObjectContent();

// Process the objectData stream.

File file = new File(keyStoreFileName);

try (OutputStream outputStream = new FileOutputStream(file)) {

IOUtils.copy(objectData, outputStream);

} catch (FileNotFoundException e) {

e.printStackTrace();

// handle exception here

} catch (IOException e) {

e.printStackTrace();

// handle exception here

}

objectData.close();

} catch (Exception e) {

e.printStackTrace();

}

}

public static Properties readPropertiesFile(String fileName) throws IOException {

FileInputStream fis = null;

Properties prop = null;

try {

fis = new FileInputStream(fileName);

prop = new Properties();

prop.load(fis);

} catch (FileNotFoundException fnfe) {

fnfe.printStackTrace();

} catch (IOException ioe) {

ioe.printStackTrace();

} finally {

fis.close();

}

return prop;

}

private static void copySSLCertificateFromS3() {

try {

Properties props = readPropertiesFile("src/main/resources/application.properties");

String clientRegion = props.getProperty("clientRegion");

String bucketName = props.getProperty("bucketName");

String sslFileNameWithPath = props.getProperty("sslFileNameWithPath");

String keyStoreFileName = props.getProperty("server.ssl.key-store");

AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(clientRegion)

.withCredentials(new ProfileCredentialsProvider()).build();

S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, sslFileNameWithPath));

InputStream objectData = object.getObjectContent();

// Process the objectData stream.

File file = new File(keyStoreFileName);

try (OutputStream outputStream = new FileOutputStream(file)) {

IOUtils.copy(objectData, outputStream);

} catch (FileNotFoundException e) {

e.printStackTrace();

// handle exception here

} catch (IOException e) {

e.printStackTrace();

// handle exception here

}

objectData.close();

} catch (Exception e) {

e.printStackTrace();

}

}

public static Properties readPropertiesFile(String fileName) throws IOException {

FileInputStream fis = null;

Properties prop = null;

try {

fis = new FileInputStream(fileName);

prop = new Properties();

prop.load(fis);

} catch (FileNotFoundException fnfe) {

fnfe.printStackTrace();

} catch (IOException ioe) {

ioe.printStackTrace();

} finally {

fis.close();

}

return prop;

}

  • Use a docker container to copy https certificate form S3 to EC2 instance. Every time we have a new EC2 instance, we can copy the https certificate file from S3 to EC2 instance using a very light weight docker container task. So far, this seems to be the best possible approach within the free tier EC2 instance of ECS type. We’re exploring this option.

If anyone has suggestions to us for a better approach, feel free to share your comments.

Strengths app part 4

This article is a part of application development series. We are providing details of creating the strength application. In part 3, we discussed about REST and other backend APIs for the application, In this part, we will discuss user interface details of the web application.

  • User login functionality: We have finalized a basic login page to authenticate a user. If a user is not authenticated and attempts to view the home page of the application, we redirect the user back to the user login page.
  • Home page: Home page provides these details:
    • User information: Name of the logged in user.
    • Number of total votes: Total votes for the user.
    • Strengths details: We show strengths of the user in a tabular form. Each row of the table has these details:
      • Strength title
      • Total votes on the strength
      • Created by
      • Buttons to view strength details, update a strength, and delete a strength

As we add more features to the application, we will update this page. Stay tuned for the updates and new articles on it.

Strengths app part 3

In the application development series part 2, we learned the use cases of this application. In this part, we’ll go through high level technical details of Spring Boot APIs and search integration of the application.

Below are REST APIs an search functionality for this application:

  • User API: It is a REST API for a user profile. It will allow to authenticate a user to view determined functionalities of the application. For example, only an authenticated user can vote on the strengths of a friend.
  • Strengths API: This API provides a feature to add, view, update, and delete a strength of a user.
  • Vote API: This API provide a feature to vote on a strength of a user. Only a friend can vote another friend’s strength.
  • Search functionality: To search a strength of a user, we’ve integrated AWS’s open search functionality. It is equivalent to Elastic Search. Strength API is integrated with open search via SNS configuration. When a strength is created, Strength API publishes a message to Elastic Search. In other words, we add a new strength entry into Open Search via SNS messaging which is integrated via Strength’s Add API method.

Later, we have a plan to add more features. We will update this page as we make more progress. Stay tuned.

In the next part, we will discuss the Desktop version User Interface part of the application.

Strengths app part 2

For the overview of the app, refer to part 1: here. In this part, we will describe the technology stack of this application.

This application is created to users who wants to learn SpringBoot, React JS, and other Java and react JS related technologies. Our approach of selecting the technologies stack is a bottom-up. That means, as we progress further, we will select teh right technology for the right module.

Technology decisions so far:

  • Rest API: We’ll build a REST API for strengths, users, and other functionalities using SpringBoot framework.
  • Web application: We’ll build a web application using react JS framework.
  • Database: We’ll use Amazon RDS based PostgreSQL database.
  • Hosting platform: This application will be deployed on AWS ECS infrastructure.
  • Search functionality: For an effective search functionality, this application will implement Elastic Search.
  • Search data feed integration: Data feed to Elastic search will be done using Amazon SNS service.
  • Cache mechanism: This is yet to be determined.

A high level architecture of the application: We’re yet to come up with a diagram for it.

This is a work in-progress page. We will update it as we make further progress with the application.

How to manage work when dealing with personal hardship

Sometimes, we’re in a difficult situation in the life. This article is to discuss some options on how to ensure we’re able to work while dealing through a difficult personal circumstances.

In my article about life principles, I mentioned the need of having a clarity of the work priorities. Many of us go through difficulties in personal life. For example, you might have an ill family member to take care of, or going through a marriage arrangement, or a divorce situation. In such difficult situations, managing work and life balance could be tough. It could be difficult to deal with the emotions at work. If you have difficulty in managing work/life balance, contact a trustworthy psychologist and other local resources to help you.

Here are few personal tips how I will deal with such a situation while not letting the work impact:

  • I will let my manager know what personal challenge I am going through. It seems simple and obvious but sometimes we miss the value of it. Even if it’s a simple personal situation that might impact the work, it helps to let the manager know about it.
  • When interacting with stakeholders (like peers, project members, or a client), it’s okay to let them honestly know, that I am going through some rough time that might impact some work. I’ll just share about the mood, not the actual problem. Also I will let them know that my intention is to do the best possible work. We all are human and we understand that anyone could be in such a situation.
  • At any situation, knowing the priority of your work deliverables is always very important. I always attempt to know the answers to these questions:
    • What’s the first, second, and third most important work deliverables expected from me?
    • What’s my first priority work deliverable today, this week, and this month?
    • If you have only 4 hours in the day, can I take care of my most important work deliverables?
  • I will work with my manager to help him/her understand what work deliverables I can realistically deliver given the personal situation. I will try to not overcommit. In fact, I will plan for 75% of the tasks that I am confident I can take care of. Reason is, we all have a tendency to overcommit.
  • At work, I will go in a transactional and a mission mode to complete the important work deliverables within the least possible time limit.
  • I will go in a bare minimum work survival mode. That could mean I will have no time to network more than required, no time to join meetings where I am not required, and no time to say Yes when I can only say No.
  • At work, I will ensure to speak only required and speak only about work.
  • I will wrap up the work in no more than planned hours. I will create a hard boundary of work and personal life. That means, I will not be able to work after the work hours. Remember. It’s a personal hardship that needs my attention after the work. So, after work, do take care of the personal situation.
  • During the work, I maybe distracted with emotions related to personal situation. I will learn to delay the decision to go back/think about the personal situation just after the work. If needed, I will schedule a meeting with myself after the work, to think through the personal situation. If I am disciplined to respect the work and personal time boundaries, I will be able to delay the personal tasks after the work.
  • I’ll definitely contact a trustworthy counselor, psychologist, or a related help, to help me deal with my situation.
  • I’ll also look for people who are in a similar situation. I will learn from them to deal with such a personal hardship and how they managed or managing their work/life balance.
  • If I am not able to work without distractions, I will work with my manager to work either part time or take time off, to take care of the situation.

As I learn more, I’ll share more.

Application development series

Strengths app part 1

This is a series of articles about developing a simple web application.

Audience: Anyone looking for basic knowledge in building a web application.

Application summary: This is a strength analyzer application. This application allows a user to add his/her strengths. It also supports additional features.

Application use cases:

  1. Maintain a user profile: A user should be able to login to view his/her information.
  2. Maintain strengths of a user: Provide a way to add/view/update/delete a strength of the user. Provide a pagination of the strengths, for a better display. The user should also be able to search strengths.
  3. Maintain a friends list: a user should be able to add other users as his/her friends.
  4. Vote and comment on a strength of the user: Friends of a user should be able to vote a strength of a user. Friends of the user should also be able to comment (post) about user’s strength.
  5. Ability to search: A user should be able to search other users by the name and on a strength.
  6. Other yet to be determined features: to be determined as we progress on the development.

Intended users (actors) of the application:

  1. A user who wants to create his/her profile to publish his/her strengths. A user could be an IT engineer, a product manager, a home maker, a business man, or anyone.
  2. A user who wants to analyze his/her strengths, to find out his/her as-is and to-be goals. For example, consider a user who is looking for a job as a UI developer. He/she is experienced in Javascript, HTML, and CSS. To get a job as a UI developer, he/she analyzes the need of learning react JS.
  3. A user who wants to feel good about his/her strengths, by gaining popularity, support, and visibility within his/her friends list.

As we learn and add more use cases, I’ll update this page. In the next part, we’ll go over implementation details.

A simple approach to solve a problem

At work and outside work, we have many situations for that we need to find a solution to a problem. Here are some example problems to find a solution for:

  • Decide the success criteria of a project.
  • Determine a career track for you.
  • Determine the decision from a data table.
  • Decide which holiday location is right for you, which is in budget and time.

Here are few techniques that I use, to decide the next steps:

  • I attempt to create a simple spreadsheet.
  • I write the desired outcome in a column or in a row, whichever you prefer.
  • I write the next possible outcome/step.
  • I continue the process until you find all your answers.
  • I revisit this process as needed.

Below is an example of a person looking for a job change as a UI developer. This person worked as a UI developer long time ago. She is interested in upgrading her skills, to get a desired job. Let’s look at the decision steps below:

ItemDetail
Desired outcomeGet a job as a UI developer
What is the first step?Analyze the current skills set
What is your current skills setI know Javascript, JQuery, CSS, and HTML
Is my current skills set sufficient to get a job at my current desired location?No
If no to previous column, what skills set needs to be added?One of these Javascript frameworks: React, Vue, or Angular
Which framework I want to learn?Not sure
How to decide which framework to learn?Do the market analysis. Understand which one is easier and attractive to learn
How to do the market analysis?Look at jobs on linkedin.com for last 30 days to analyze which one is most and least popular
What is the outcome of the analysis?React is the most popular in my area
How can I learn React JS?1. Find a tutor or an online course
2. Get a book
3. Plan for a dummy project
4. Find time to learn
How much time I need to learn this skill realistically?I will need to read a book. I will need to get an online course too. I will need to create a dummy project also. Reading a 300 page book will take at least 6 hours for me. An online course will need 6 weeks, with 4-6 hours commitment every week. To create a dummy project, I need at least 40 hours. In total, I am looking for roughly 70 hours. Let’s plan for 80 hours. In a week, I can spend no more than 5 hours. With that calculation, I need 16 weeks. It is roughly around 4 months.
Note: I may need time to refer to online resources. I should also plan for at least two weeks unplanned. With this speed of learning plan, I need around 5 months to learn react JS. To learn it quicker than 5 months, I need to increase learning hours per week or reduce the scope of learning.

This is just a basic example of one of an example problem. Depending on the situation, it’s ok to create a flowchart, a decision tree, or a more detailed spreadsheet format. Some possible steps could be to consult a friend or an expert. Add all such steps and update the status of it.

Thank you. As I learn more, I will update this article.

Create your own life principles

I believe everyone should create their own life principles. They’re not just words on paper — they guide your decisions, help you stay focused, and make life simpler when things get messy.

When I think about it, life is full of distractions, pressure, and endless choices. Principles give you a compass. They tell you what’s worth your energy and what’s not.


Why Life Principles Matter

Having clear principles helps you:

  • Make decisions faster and better.
  • Stay aligned with your values instead of reacting to circumstances.
  • Live with purpose rather than chasing short-term goals.

Stephen Covey, in The 7 Habits of Highly Effective People, talks about living a principle-based life. Basically, a life guided by principles is more fulfilling than one based on money, approval, or temporary achievements.


How I Approach My Life Principles

Here’s how I think about mine — and it might help you create yours:

1. Know Your Core Values

Figure out what matters most to you. For me, it’s service and perseverance — with service as the top priority. These are the foundation of everything I do.

2. Pick Your Focus Areas

Decide which parts of life get your attention. Mine are spirituality, fitness, finance, and relationships. Everything else is secondary.

3. Make an Ignore List

Knowing what you won’t focus on is just as important. For example, I avoid watching TV after 10 PM. This frees up energy for things that actually matter.

4. See Life as Service

Approach life as an opportunity to help and serve — at work, at home, with friends. Service gives purpose to everything you do.

5. Write Daily

Writing in a journal every day helps me clarify my thoughts, plan my actions, and stay on track. Even 10 minutes is enough.

6. Do Minimum Work First

At work, I focus on completing the essential tasks first. Once those are done, I can go beyond. It reduces mistakes and keeps priorities clear.

7. Enjoy Every Moment

Don’t wait for big milestones to enjoy life. Find joy in work, learning, and even small daily routines.

8. Value Humor

Humor keeps life light and perspective intact. Don’t underestimate it.

9. Focus on the Journey

Success isn’t just about results. The process, lessons, and small wins along the way matter just as much.

10. Separate People from Situations

In conflicts, address the problem — not the person. It makes resolving issues easier. People often act from their own fears, stress, or circumstances. I attempt to pause and respond with awareness, because people may forget the situation—but they remember how I made them feel.

11. Plan and Visualize

All things are created twice — first in your mind, then in reality. Visualizing what you want helps you take action with clarity.

12. Remember Problems Are Temporary

Challenges come and go. Solutions are always possible, even if it takes time.

13. Service First, Gratitude Second

If I can do only two things in a day, I focus on helping others first, then reflecting on what I’m grateful for. Ending the day with gratitude keeps me grounded.

14. Ask for What You Want

People often miss out because they never ask. Be clear and bold about your needs.

15. Believe in Human Potential

If someone can imagine it, they can do it. This applies to you too.

16. Persistence Wins

Consistency matters more than short bursts of energy. Keep going, step by step, even if progress feels slow.


Final Thoughts

Life principles aren’t about following someone else’s rules. They’re about deciding what’s important to you and sticking to it.

When you live by your principles, decisions get easier, life feels simpler, and challenges become opportunities.

Start small: pick 3–5 principles today. Write them down. See how they change the way you live.