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

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 unlike VM.
Some key points about docker
  • Docker consists of a docker file which contains all the applications dependencies written by the dev. Docker file builds a docker image that contains all the project's code. We can run that image to create as many docker containers.

    Docker file -> Docker image -> start container
  • Docker image can be uploaded to docker hub from where anyone call pull and build a container.
  • Docker containers are run time instance of docker image.

            Docker file --->   Docker Image  -------> Docker hub
                                                      I
                                                      I
                                                      I
                                            Docker container
  • General approach used for implementing dockerization is as below:

                                                                                    ----> Testing
    Docker File ---> Git repo  --> Jenkins server          ----> Staging
                                                                                     -----> Production                                                                                                                                    
Docker file is present in the git repository of the oraganization and is then used to create containers in the different environments.
  • Docker Registery : Docker has its cloud based registry docker hub where you can upload public/private images
  • Docker compose : Docker compose makes it easier to run applications made up of multiple containers. Multiple applications on containers and you want to run them with one single command ; compose helps in this. Example: If you application has webapp container,other container running redis,mysql

           webapp container ----->
                                                                                            DOCKER COMPOSE
           mysql container ------>

           redis container  ------>

       Create a docker-compose.yml to define dependencies between containers.
       Use command sudo docker-compose up -d ; this command will pull images and build containers as given in docker-compose.yaml
  • Commonly used docker commands :
## List Docker CLI commands
docker
docker container --help

## Display Docker version and info
docker --version
docker version
docker info

## Execute Docker image
docker run hello-world

## List Docker images
docker image ls

## List Docker containers (running, all, all in quiet mode)
docker container ls
docker container ls --all
docker container ls -aq

## To build a dockerimage
docker build -t myDockerImage .

## To run a dockerimage
docker run -p 4000:80 myDockerImage
## 4000:80 -> this basically maps exposed port 80 of your container to port 4000 of your host OS

## To run image in silent mode
docker run -d -p 4000:80 myDockerImage

## Tagging and publishing the images
docker tag image username/repository:tag
docker push username/repository:tag

## To pull image and use it on any machine:
docker run -p 4000:80 username/repository:tag

## To pull images and build containers as given in docker-compose.yaml
docker-compose up -d


                                              




Comments

Popular posts from this blog

Guice Tutorial

Introduction to Kafka

Ruby Syntax Cheat Sheet