Akash's Blog

_

Tuesday, February 11, 2025

System Design Series: Scalability

Introduction

Scalability means system's capability of handling more work. 

Consider an example of a website where there is one server handling 1000 users. Due to some reason more and more users are opening the website and suddenly the number of users increased to 50,000. However, the system is not capable of handling more than 50,000 users. In this case if load further increases, the system will fail to serve the users, it may crash.

We can solve this problem primarily in two ways. We can either scale the system Vertically or Horizontally

Vertical Scaling

When we increase the capacity of the server to handle more work is considered as vertical scaling. 

Vertical Scaling











Pros

  • Easy to maintain as there will be fewer components in the system.

Cons

  • Capacity increase comes with additional cost which increases rapidly for large scale systems.
  • There is an upper limit till which only you can scale.
  • Single Point of Failure. 

Horizontal Scaling

When we increase the number of servers to handle increasing work, is considered as horizontal scaling. By increasing the number of servers we can (evenly) distribute the load amongst these servers to handle more work using the load balancer. 

Horizontal Scaling












Pros

  • Can solve single point of failure problem.
  • Highly scalable and available.
  • Comparatively cheaper as few small servers are cheaper compared to one high end server.

Cons

  • Added complexity in deployment and maintenance.


Monday, February 10, 2025

Devoxx Belgium 2024 : Java Performance Update



Introduction

A high level summary and commentry on the aforementioned Java 24 performance update video. Java is not just updating it's performance and usability in general but moving way faster year on year. The Java 25 is likely to be released somewhere in 2025. 

This video is of last year Devoxx but recently posted on Java Youtube channel and as a curios Java follower I found it very interesting, thus I decided to write about it on my blog. This video initially gives summary of Java projects, performance metrics, challenges faced in performance and then shared the recent and future performance improvements. If you don't want to get into initial summary and focus on recent performance improvements you can start from here.

Ongoing Java Projects

Speaker summarized the ongoing Java projects which are listed below,

  • Amber : Small Java Features.
  • Babylon: Extend reach of Java to SQL, ML Models and GPUs.
  • Leyden: Improve start up time and reduce memory foot print.
  • Lilliput: Reduce size of Java Object Header on 64 bit architecture.
  • Loom: Lightweight concurrency.
  • Panama: Integration between Java and system level programming languages.
  • Valhalla: Augmenting java object model with value objects.

Metrics / Challenges / Tools

In this section speaker briefed about the different metrics one need to consider while checking for performance. Performance needs to be looked from wholestic view which must include usage of memory, CPU, threads, cache and power. Also, start up and warm up time needs to be considered while measuring the performance.

While talking about challenges speaker emphasized that we can not get accurate performance statistics on our laptops it's better to do it on dedicated server post warm up when application is ready to serve. That too one should not consider the result after very few runs, performance results needs to be collected after thousands of executions. Also, suggested to use System::nanoTime instead of System::currentTimeMillis for better accuracy while checking the performance.

Speaker mentioned about JMH (Java Microbenchmark Harness) which can be used to get micro level benchmarking using @Benchmark annotation. He further talks about the internal tools which Java team uses to check the benchmarks in different platforms which gives them an idea of how much the performance improve or degraded in respective platform.

Performance Improvements

JDK-8318446: C2 - "MergeStores"
This is an internal fix to the Java Hotspot Compiler (C2), improvement in terms of array store operations. 

Array store operation refers to process of writing values to the array index. Earlier the compiler was merging primitive stores such a way which was causing assertion failures and even incorrect optimizations. 

Using Unsafe and BALE (Internal to JDK, jdk.internal.util.ByteArrayLittleEndian) were alternatives but both are not good considering Unsafe is something we should move away from and BALE may slow down things.

JDK-8340821: FFM API Bulk Operations
This includes performance enhancement in Foreign Function & Memory (FFM) API. The basic idea was to handle specific memory segments code directly in Java instead of using native code. By reducing the overhead of converting native code to Java.

JDK-8180450: Secondary Super Cache Scaling
This was a bug in secondary super cache. Specifically in instanceof operation when multiple threads frequently checks the type in succession the cache was becoming unstanble and overall performance was hammered in rare workloads. 

JDK-8336856: String Concatenation
Before this enhancement Java would do extra calculations especially with different data types like int, long, double etc. which was slowing down the overall concatenation. After this change Java has reduced unneccessary work to improve the overall performance.

JEP-474: ZGC
This change in ZGC (Z Garbage Collector) aims to enhance performance by focusing on generational garbage collection, which manages short-lived and long-lived objects more efficiently. Moving in a direction to make generational GC mode as default.

JEP-450: Compact Header
Reduce object header size to save ~20% memory. Considering, approx header sizes are around 12-16 bytes and object sizes are 32-64 bytes.

Summay

This video was having many things which were new to me. It helped me in getting more understanding of internal workings and progress happening around the performance aspect. I tried to simplify these updates as much as possible. I may dig down into each going forward for more in depth learning and better understanding.

Apparently, there are other improvements also mentioned which will be the focus for upcoming months on top of these. These updates may look abstract and at first, may sound not making huge impact but by taking a close look it's moving in a direction of high optimization and efficiency.




Sunday, February 9, 2025

Three at Thoughtworks



Introduction  

It's been three years since I became a part of Thoughtworks. I wanted to write about my experience after my first work anniversary, but I felt one year was too little and five years too much to reflect on my journey in an organization. So, I decided to write about it at the sweet spot between one and five years.  

Sometimes, I regret not joining this company earlier in my career. Perhaps I wouldn't have made it back then, but anyway, I am here now and truly enjoying my journey of growth. This post is not about claiming whether Thoughtworks is a good or bad place to work—rather, it's about my journey in an organization that has been in the tech industry for more than three decades. These are my personal views and experiences, which may differ from others working at Thoughtworks, but I hope many will find them relatable.  

Life Before Thoughtworks  

Before joining Thoughtworks, I worked in two organizations—one service-based and the other product-based. In both, I learned a lot and kept improving day by day.  

I feel my first organization, SPEC India, played a key role in shaping my interest in programming. I am always thankful to them for their support and guidance—without those early experiences, I wouldn't have found my direction. Due to certain personal reasons, I had to switch to Infostretch (QMetry), which is now acquired by SmartBear. Here, I developed a better understanding of software products and gained exposure to client communication and leadership.  

By the time I considered joining Thoughtworks, I believed I knew a lot. My confidence, or rather ego, kept thriving. I was doing things well, but I was doing them the way my previous organizations expected me to. You may ask, what's wrong with that? The answer is nothing, but at the same time, not everything was right either.  

The Interview Process  

When I decided to switch job in 2021, I applied to multiple companies, including Thoughtworks. The interview process was tiring, to be honest, but things are a bit different now as per my knowledge. It took me five rounds to get through, starting with:  

  1. Code assignment  
  2. Code pairing  
  3. Two technical rounds to assess depth and breadth  
  4. Leadership and cultural alignment  

The interviews challenged my core skills and tested my abilities to the limit, making me realize how little I knew and how much more I should know. The expectation was not to answer everything correctly, but I struggled when I couldn't answer multiple questions—especially when my depth and breadth of knowledge were tested. I wouldn't say I completely failed, but I definitely didn't succeed with flying colors.  

After each round, I received detailed feedback from the recruiter, helping me understand my standing. I remained somewhat positive about making it through, and eventually, I did. I received the offer and accepted it without any negotiations.  

I joined Thoughtworks on December 31, 2021, keeping my promise to myself that I wouldn't be in the same company by the end of 2021.  

Life at Thoughtworks  

Journey So Far  

My journey at Thoughtworks has been filled with learnings and challenges, yet I feel like it's just the beginning. I'm on a path to becoming a better professional, and Thoughtworks is playing a key role in shaping that.  

Immersion  

Immersion is a four-day program that every new Thoughtworker attends. It gave me a glimpse of the Thoughtworks way of working, and I got to learn from the journeys and experiences of other Thoughtworkers. The program prepared me for the role of a consultant and helped me understand Thoughtworks' culture.  

It may sound like a formal, instruction-heavy program, but it was fun, interactive, and filled with games, insights, and refreshing conversations, making it very engaging.  

Dev Bootcamp  

The Dev Bootcamp was organized for all new developers to introduce them to TDD, Pair Programming, XP Practices, and Trunk-Based Development. The trainers handheld us through the process, ensuring we understood the whys, whats, and hows really well.  

Culture  

As I started interacting more, I realized that multiple things are deeply rooted in the Thoughtworks culture. People willingly follow these principles, such as:  
  • Being the sailor of your own ship of ambitions  
  • Being open to giving and receiving feedback  
  • Being ready to take on different roles  
However, coming from a different work environment, I initially felt a slowdown in productivity. I was doing less work compared to my previous organizations, but my quality of work and engagement gradually improved. The culture here expects you to balance work and continuous learning.  

Community  

I'm not sure if I can go into too much detail in this post, but I can summarize my experience.  

Thoughtworks has several thriving communities covering technical and non-technical skill sets. Anyone is free to join and contribute. It’s not just about learning new things—it’s also about collaborating with like-minded people.  

Apart from learning, these communities help you solve real-world problems. If you ever face challenges on a project, you can reach out to the global Thoughtworks community for help.  

People  

Since joining, I’ve had the opportunity to work with and learn from many talented people. I've gained insights from their perspectives and also helped others to whatever extent I could.  

The people at Thoughtworks are not fundamentally different, but the environment they are placed in brings out their best potential. The feedback culture here helps maintain team health and improve collaboration.  

Overall, I have found the people to be cooperative, inclusive, and supportive so far.  

Work  

The work at Thoughtworks can be challenging, depending on the assignment. I struggled to cope with the diverse tech stacks and the variety of domains I had to study.  

Each project was unique and left a different impression on me. The pace is fast, and you are continuously challenged to be adaptable and flexible.  

Summary  

Thoughtworks has changed the way I perceive technology and consulting. Although I faced challenges adapting, the company provides access to resources and people that help you find solutions faster through connections and community.  

That said, Thoughtworks is not a perfect company—no company is. There are ups and downs, just like anywhere else. However, one commendable aspect is its strong stance on diversity, inclusion, and equality, which has been a core value from the very beginning.  

Thursday, January 23, 2025

Auto push to Git on Mac

Introduction

For periodically syncing changes of your Github repository you can automate the process using a script and crontab on Mac OS. It's really quick and simple if you don't have more complex requirements. Note taking is one of the use cases where you want periodic sync to take place automatically to ensure notes are pushed to the cloud without any manual steps.

Setup

1. Open terminal and type crontab -e this will open an editor where you can specify which script to execute, here we want to push our changes so we will point it to that script. Here we have used cron expression "* */2 * * *" which will execute the script every two hours. You can use crontab.guru to generate the expression as per your requirement.

* */2 * * * /path/to/sync.sh >> /path/to/logs/run.logs 2>&1

Save the changes. (Type :wq! to save) 

File sync.sh should be accessible and hold required permissions. Use chmod command to update the permission to necessary state.















2. Define sync.sh in following way to push your changes. Prerequisite is that you have cloned and setup required github repository in respective folder.

#!/bin/bash

set -e

cd /path/to/repo

BRANCH="main"
COMMIT_MSG=${1:-"Update"}

 if [[ -n $(git status --porcelain) ]]; then
    echo "Changes detected."
    git add -A
    git commit -m "$COMMIT_MSG"
    git push origin "$BRANCH"
    echo "Changes pushed successfully!"
else
    echo "No changes to commit."
fi

Important Note
Note that this script syncs all the changes of given repository. Do not add sensitive information like credentials, tokens or anything which you do not want to get synced especially on public repository if that is the case.

Monday, January 20, 2025

Clone all GitHub Repositories of the User

Cloning all the repositories of the user is not something that you would need very frequently but for personal repositories it comes very handy as I don't need to clone individual repositories. Similarly while working with any organization this saves lot of time of individual cloning. Having said that you may need required access and permission to the account and organization as we will going to use the user token to clone the repositories.

Generate Access Token

The first step is to create a personal token which can allow us to access our repositories through API.  We can generate the token from Settings > Developer Settings > Personal Access Token. Here we will going to use classic token for better understanding and simplicity.















Run script to Clone

Following script can be used to clone all the repositories. It uses jq command to process the response of the github API which you may need to install if not done already. Basic idea is to call the GitHub API, fetch list of repositories, iterate over the repositories and clone each in given directory.  Update GitHub username and token in following script and execute it.

#!/bin/bash
GITHUB_USERNAME=""
GITHUB_TOKEN=""
# GITHUB_ORG=""

API_URL="https://api.github.com/user/repos"
# For organization use following
# API_URL="https://api.github.com/orgs/$GITHUB_ORG/repos" 
PAGE=1
PER_PAGE=100

mkdir -p allrepos
cd allrepos || exit

while :; do
  REPOS_TO_CLONE=$(curl -s -u "$GITHUB_USERNAME:$GITHUB_TOKEN" "$API_URL?per_page=$PER_PAGE&page=$PAGE" | jq -r '.[].clone_url')
  
  if [ -z "$REPOS_TO_CLONE" ]; then
break fi echo "$REPOS_TO_CLONE" | while read -r repo; do
git clone "$repo" done PAGE=$((PAGE + 1)) done echo "All repositories are cloned successfully!"

This script may take time depending on the number of repositories given user or oganization have. You will see success message once all repositories are cloned.

↑ Back to Top