Posts

Docker Container Orchestration

Image
In my previous post we saw the fundamentals of what docker is and some basic commands here .  Docker has evolved multifold since then. Different features like stack, services, swarm mode has been added. Today we are going to talk about the container basics and the new features as well. So what is Container? Container is an isolated area of Operating system running an instance of code or software. This isolated area has resource limit applied. In docker container world there are two fundamental concepts: Namespaces : represents isolation. Control group : grouping of resources and applying limits. Namespaces: When you run a container, docker engine creates a set of namespaces in background to provide isolation from other containers. Process Id (pid):  It assigns pid to the processes within the docker container. These process id's are independent of other processes in other namespaces for.e.g net or mnt. Network (ne

Rust: Smart Exception Handling with Result

Image
Exception Handling: When I started working on computer systems or especially programming, one thing I used to hear from colleague or friends "My code is broken" or In  Hindi "Code fat Gaya". I have worked in such scenarios where the code is not working on production system and had to look into the logs for any Exception stacktrace or Errors statements that I can check.  You must agree with me that intelligently reading and analyzing the logs is an art . When working with Rust there are two types of Errors  panic! (Unrecoverable errors) Result<T,E> (recoverable errors) panic!:  Unrecoverable errors can occur anywhere. It may be because of bug in your code or in the library you are using. When such a situation occurs Rust calls Panic macro (! symbol is for macro). After calling panic, it tries to undo the changes that the program did (called as Unwinding) and then exit. But if its large program the Unwinding may take

Rust: starting with blazingly fast programming language

Image
 How I heard about Rust. As a regular user/contributor of one of popular tech forum stack overflow , I read almost all the blog post on stack-overflow. Every year they hold programming survey and Rust is on top since last 4-5 years. you can read about this survey here . First look: As a curious user, I tried to take a look at the language website , which talks about why Rust and many other things. First question came to my mind was, why another language?  what are we trying to solve? there are many other languages out there along with popular frameworks and thriving developer communities .  I come from Java development background and have been building web-apps since 2012. So the first statement that caught my attention, is that its blazingly fast . What is it that makes Rust so fast? Static typing:  Its statically typed language. So Rust compiler knows

Advanced wiring in Spring Part-2

Image
In the last article we have seen that how we can configure beans based on certain environments.This is quite useful features spring have provided.Sometimes we need more granular control over the bean autowiring in spring, such as we need certain beans that needs to be autowired or injected on some complex condition (which is something more than certain environment). for e.g. What if we need certain bean needs to be injected if some other bean have specific property value. or inject an bean only if some other class is found on class-path. Here Spring will help you to make such a configuration using @Conditional annotation. Suppose we want the bean OperationUser to be created if the property " department= Operations " is set in your properties file. @Bean @Conditional(OpsDepartmentCondition.class) public OperationsUser operationsUser(){ OpeartionsUser opsUser = new OperationsUser(); return opsUser; } We will take a look at how OpsDepartmentCondition will

Advanced wiring in Spring

Image
Many times we face situation in which we want certain things configured as per the environment or on certain complex condition. Spring provides great features in easing the developer job for this use-case. We will look at such a scenario along with solution spring provides in this case. Environments and Profiles: One of the most challenging part of any application is to transitioning of the software into different environments (DEV, QA, STG, PROD). Certain choices that we make in DEV environments are not suitable when we run the same setup on PROD environment. Consider basic use of using different database as per the deployment environment. for DEV we might setup a datasource something like below: @Bean(destroyMethod = "shutdown") public DataSource dataSource() { return new EmbeddedDatabaseBuilder() .addScript("classpath:devCreate.sql") .addScript("classpath:devInsert.sql") .build(); } but when we will go on PROD environment, this c

Docker fundamentals

Image
Nowadays everybody is talking about Docker. Some people are well versed with docker concepts and have hands on it and some have started learning docker. So what is Docker?. As per the official docs from docker, Docker is a platform for developers and sysadmins to develop , deploy , and run applications with containers. So what does make it different. We were already doing that since long . When we are deploying application on servers we have to deal with setting up new VM , configuring dependencies / libraries, environment variables. Docker makes this thing easy for you, by providing OS level virtualization (aka. containerization). So basically you can create Docker images that will have all your resources ( env. variables / libs / running on what port). Then you can deploy your application inside docker container anywhere without even worrying about the dependencies. In traditional way you have to setup separate VM and then install all the required software and have

Spring RestTemplate : Follow Redirect Automatically

Follow Redirect Automatically in Spring RestTemplate.... Now since the boost of micro-service based architecture we use web-services a lot. Spring boot is one of the popular framework to work on Micro-service based architecture. Soap web-services are legacy swords and REST( Representational State transfer ) is now the modern time weapon in everybody's arsenal. When we use REST with Spring we have lot of inbuilt functionalities (Converting Response and request to Domain objects, Error handling, HttpStatus code and many more...) offered by Spring. Today we are going to check about RestTemplate. Spring's central class for synchronous client-side HTTP access. This is what Spring says about RestTemplate. RestTemplate provides support to all HTTP Methods. Most popular are GET and POST. So when we are calling any webservice endpoint using RestTemplate GET or POST there are chances that in response you get Redirect response (302 HTTP Status code). Which indicates that this