Posts

Showing posts from November, 2018

Domain Modelling Patterns

Image
There are two main patterns for organizing business logic: the procedural Transaction script pattern, and the object-oriented Domain model pattern. 1. Transaction script pattern: An important characteristic of this approach is that the classes that implement behavior are separate from those that store state. When using the Transaction script pattern, the scripts are usually located in serviceclasses, which in this example is the OrderService class. A service class has one method for each request/system operation. The method implements the business logic for that request. It accesses the database using data access objects (DAOs), such as the OrderDao. The data objects, which in this example is the Order class, are pure data with little or no behavior. This style of design is highly procedural and relies on few of the capabilities of objectorientedprogramming (OOP) languages. This what you would create if you were writing the application in C or another non-OOP language. Neverthe

Ruby Syntax Cheat Sheet

In this post I am sharing out a short and concise cheat sheet to help you learn or reminisce ruby syntax and constructs. 1. To print multiple Lines print <<EOF    This is the first way of creating    here document ie. multiple line string. EOF 2. To run in the beginning of program BEGIN {    puts "Initializing Ruby Program" } 3. To run at the end of the Program END { puts "at end" } 4. Class in Ruby class Customer end cust1 = Customer.new 5. Local variable start with lowercase or _ instance variable start with @ class variables start with @@ global variable start with $ 6. When you plan to declare the new method with parameters, you need to declare the method initialize at the time of the class creation. The initialize method is a special type of method, which will be executed when the new method of the class is called with parameters. Here is the example to create initialize method − cla

DropWizard Tutorial

Image
In this article I will discuss about dropwizard , how to implement a simple application using dropwizard. Dropwizard is a simple tool to develop reliable web applications with minimal maintainance and is easy to learn,implement. It includes: Jetty, a high-performance HTTP server. Jersey, a full-featured RESTful web framework. Jackson, the best JSON library for the JVM. Metrics, an excellent library for application metrics. Guava, Google’s excellent utility library. Logback, the successor to Log4j, Java’s most widely-used logging framework. Hibernate Validator, the reference implementation of the Java Bean Validation standard.   Moving head on to the implementation part ; each dropwizard application must have below components to expose rest api(s): 1. Configurations in yaml format 2. Application configuration (This contains all the configuration files required by your application ) 3. POJOs required for data transmission 4. Resource Files to expose your apis

About Docker

In this post we are going to give a short introduction to docker. This post will probably help you in getting to know about the gist of docker as a developer. Why docker? Problems before docker: Without docker we had to deploy our webservice on Virtual Machines which required 1 Virtual Machine per each microservice ; wastage of ram,disk space for each virtual machine In docker there is a single VM, there are docker containers on top of it. Docker Containers are lightweight and requires no pre-allocation of resources unlike Virtual Machines. You might be thinking that why use VM here with docker containers? To segregate the required amount of memory and disk space for the containers and also if its a windows machine we need to provide linux environment though VM as docker runs on linux. Provides consistent development environment for dev,test throughout SDLC On top of host OS there is docker engine and top of it there are multiple docker containers. Docker does not have own OS

GraphQL Introduction

Image
In this post I will give a brief introduction to graphQL.Please go thoroughly with the introduction shared in a short and concise manner below as in the next post we will have a look at actually implementing a server using graphQL in Java. What is GraphQL? GraphQL is a new API standard which provides more powerful and flexible alternative to REST. It Enables declarative data fetching (Client can tell exactly what fields to fetch). Exposes a single endpoint and responds to queries unlike REST It solves below problems :                  underfetching: An endpoint doesn't return sufficient information; need to send                                                     multiple requests to server                  overfetching: Downloading unnecessary data Let's say you have an entity called product with attributes productId, productname ,price,productSeller No need to adjust api if product requirement or design changes Fields which are not required by client also easily v

Mysql Replication

Image
What is Replication of mysql database? Replication enables data from one mysql server (master) to be copied to on or more Mysql database servers (slaves).Replication is asynchronous by default; slaves do not need to be connected permanently to receive updates from the master. Depending on the configuration, you can replicate all databases, selected databases, or even selected tables within a database. What are its benefits? It helps your application to scale ; you can perform write operations solely on master and read operations on the slaves only in order to improve the performance of writes on the master. For data replication and security purpose There are two methods of replication: 1. Traditional method in which slave replicates the events from the master's binary log file . It requires the log files and positions in them to be synchronized between master and slave. 2.The newer method based on global transaction identifiers (GTIDs) is transactional an

Kafka terminal commands cheat sheet

Cheat sheet for commonly Used Kafka Commands: 1.Start the Zookeeper server by executing the command: bin/zookeeper-server-start.sh config/zookeeper.properties 2.Start the Kafka server by executing: bin/kafka-server-start.sh config/server.properties 3.Create a topic bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic topic_name 4.Start a simple console consumer that can consume messages published to a given topic kafka/bin/kafka-console-consumer.sh  --bootstrap-server localhost:9092  --topic topic_name --from-beginning 5.Start up a simple producer console that can publish messages to the topic_name topic: bin/kafka-console-producer.sh --broker-list localhost:9092 --topic topic_name Please suggest in comments to add any other kafka terminal command that you use frequently.

Scaling out your application using Kafka

Image
In the previous post we talked about the basic terminologies of kafka. One important term we defined was groupid which allows one consumer within the consumer group to consume the event. Use case of groupId concept : In real world applications we have consumer running on multiple machines (maybe even in mutiple threads) subscribed to the same topic and each machine is running the same application logic or code to consume and process the event ; but we would want the event to be consumed and processed on same machine i.e only once and not by every consumer of every machine. This can simply be achieved by assigning the same groupId to all the consumers of that topic. Example : Let's say the myFood Matching application has the logic to make a call to tracking delivery boy application and to make some entry for the response in some database. If you don't assign the groupid all the consumers(machines) would consumer the same event and make calls and multiple entry in db.

Introduction to Kafka

Image
Below and the following blog spot will not only give you a kick start about the working of kafka but also give you a fair idea about how it can be used to scale out your application in production. Kafka is a pub-sub (publish-subscribe) messaging system which can be used for messaging passing to develop highly scalable and fault tolerant applications. Here I will start with the basic introduction to kafka in this post and will move further to the designing and development part. Let's say you have a food delivery app where there are different systems which needs to interact with each other and needs to do some type of message passing ; better understood from the architectural diagram below: This is an overly simplified architectural diagram where you have your consumer application from where your customer actually places an order for a particular food item and from a particular restaurant. You have a matching logic right in the middle block which matches the driver with