Saturday, May 22, 2021

Monolithic vs Microservices

👉    Monolithic Architecture.

*    Monolithic architecture was there before Microservices came into action. 

*    All functionalities or services are implemented or deployed into a single server or the software application.

*    For example lets consider a shopping platform.


👉    Characteristics of Monolithic Architecture.

*    Developed and deployed as a single unit.

*    Overwhelmingly complex.

*    To update a service need to redeploy the entire server/application.

👉    Problems in Monolithic Architecture.

*    Complexity of the architecture.

*    Unable to scale the server/application.

*    Non-reliable.

👉    Messaging in Microservice Architecture.

*    Function calls/language level methods.

*    SOAP and WS with HTTP, JMS.

👉    Microservice Architecture.

*    Developing a single application as a suite of fine-grained and independent services which runs on its own process, developed and deployed independently.

*    For example consider the same shopping platform application.



👉    Characteristics of Microservice Architecture.

*    Single responsibility.

*    Independent development and deployment.

*    Focus on the scope of microservice.

👉    Messaging in Microservice Architecture.

*    Simple and lightweight messaging mechanism.

*    Both synchronous and asynchronous messaging.

*    Message formats are JSON, XML.

*    Service contracts like Swagger, RAML, Thrift.

👉    Integrating Microservice Architecture.

*    SOA/web services use ESB

*    But in microservices it is different.

      1.    Point to Point style.


      2.    API Gateway Style.

      3.    Message Broker.


👉    Governance in Microservice Architecture.

*    No centralized governance in microservices.

*    Make their own decisions about design and implementation.

👉    Service Registry in Microservice Architecture.

*    Holds the microservice instances and their locations.

👉    Service Discovery in Microservice Architecture.

*    Find the available microservices and their corresponding locations.

*    There are two types:
    1.    Client side discovery.
    2.    Server side discovery.

👉    Deployment in Microservice Architecture.

*    Ability to deploy/undeployed independent of other microservices.

*    Example : Docker.

👉    Security in Microservice Architecture.

*    Security component implemented at each microservice level.

*    OAuth : Access token with no user identification information.

*    OpenID connect : ID token with user infromation.

*    Microservices do  not support transactions due to complexity.


Sunday, May 9, 2021

Creation of the backend with REST API and MongoDB in the MERN Project

 ðŸ‘‰    Hope you have read and tried out connecting mongoDB with your application through the steps available in my previous blog post.

 ðŸ‘‰    Today lets move one step forward and create the backend services [without the frontend UI] and execute them through postman.

 ðŸ‘‰    Lets follow the same procedure of listing the steps in point form which is easy to catch-up things.

 ðŸ‘‰     Pre-conditions to start the project.

1.    VS code installed in the local machine.

2.    Node JS installed in the local machine.

3.    Installed MongoDB with MongoDB Compass into the local machine.

4.    An instance of MongoDB running in the local machine.

5.    Have a cluster created in the MongoDB Atlas with the current IP address active in it [Refer the previous post to set the current IP address in the network access in cluster.

 ðŸ‘‰     Now lets get started.


🔑    Step 01 - Setting up the folder.

*    Create a folder in the desktop or any subdirectories.
*    Open the folder in VS code.
*    Create another folder called 'backend' below the main folder using command 'mkdir backend'.

🔑    Step 02 - Installation of necessary packages and libraries.

*    Open a new terminal.
*    Run the command 'npm init' and create a init project.
*    Then run the command 'npm install express mongoose'. This command installs express and mongoose into the init project.
*    Then run the command 'npm install nodemon'. This command install nodemon which is useful to auto-save the changes to the server without stopping and restarting it.
*    After installing the nodemon navigate to 'package.json' and edit the 'scripts' tag as following.

"scripts": {
    "start""node app.js",
    "devStart""nodemon app.js"
  }

*    Finally install cors in order to handle JSON inputs and outputs by issuing the command 'npm install cors'.
*    After installing all these packages and libraries the 'package.json' file looks as shown below.

{
  "name""server",
  "version""1.0.0",
  "description""",
  "main""index.js",
  "scripts": {
    "start""node app.js",
    "devStart""nodemon app.js"
  },
  "author""",
  "license""ISC",
  "dependencies": {
    "cors""^2.8.5",
    "express""^4.17.1",
    "mongoose""^5.12.7",
    "nodemon""^2.0.7"
  }
}

🔑    Step 03 - Creating the schema.

*    Now lets create a schema (table) in MongoDB named as 'Student'.
*    First, create a folder inside the main folder named 'model'.
*    Create a file named 'Student.js' inside the model folder.
*    Type the following code inside the Student.js file.

const mongoose = require('mongoose');

const StudentModel = mongoose.Schema({
    studentName: {
        type: String,
        required: true,
    },
    studentFaculty: {
        type: String,
        required: true,
    },
});

const Student = mongoose.model("Student",StudentModel);
module.exports = Student;

*    This code creates a schema names 'Student' inside the DB created inside the cluster.
*    The Student schema has 'studentName' and 'studentFaculty' as the columns.

🔑    Step 04 - Connecting to MongoDB cluster.

*    Now create a file named 'index,js' inside the 'backend' folder.
*    Type the following command to connect to the database.

onst express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const app = express();

app.use(express.json());
app.use(cors());

/**The Database connection */
mongoose.connect("<Link of MongoDB cluster for connecting with the application>", {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useFindAndModify: true,
});

app.listen(3001,() => {
    console.log("Server is started and running on 3001");
});
*

*    These are the main steps involved in setting up the backend. Now lets perform HTTP requests (GET, POST, PUT and DELETE).

🔑    Step 04 - POST Method - Adding a student.

*    The following code shows the import the schema to 'index.js' file.

/**Importing the model */
const StudentModel = require('./model/Student');

*    Type the following code to perform the POST functionality.

/**Post - Add Student  */
app.post("/insertStudent"async (reqres=> {
    /**Provide same name as per the column name */
    const name = req.body.studentName;
    const faculty = req.body.studentFaculty;

    const std = new StudentModel({
        studentName: name,
        studentFaculty: faculty,
    });

    try{
        await std.save();
        res.send("Inserted Data!!");
        console.log("Data inserted successfully!!!");
    }catch(err){
        console.log(err);
    }
});

🔑    Step 05 -GET Method - Getting student details.

*    The following code can be used to get the student details.

app.get("/readAllStudents"async (reqres=> {
    StudentModel.find({}, (error,result=> {
        if(error){
            res.send(error);
        }

        res.send(result)
    })
});

🔑    Step 05 -GET Method - Getting particular student detail by id.

//Read student details by ID
app.get("/readStudentById/:id"async (reqres=> {
    const id = req.params.id;

    StudentModel.find({_id:id}, (error,result=> {
        if(error){
            res.send(error);
        }

        res.send(result)
    })
});

🔑    Step 06 - PUT Method - Update particular student detail by id.

//Update the workshop details
app.put("/updateStudent"async (reqres=> {
    const studentNamereq.body.studentName;
    const studentFacultyreq.body.studentFaculty;
    const id = req.body.id;

    try{
        await StudentModel.findById(id, (errupdatedStudentObject=> {
            updatedStudentObject.studentNamestudentName;
            updatedStudentObject.studentFacultystudentFaculty;

            updatedStudentObject.save();
            res.send("Student detail Updated Successfully");
        });
    }catch(err){
        console.log(err);
    }
});


🔑    Step 06 - DELETE Method - delete particular student detail by id.

/**Delete the student details from  the student Schema for given student ID */
app.delete("/deleteStudent/:id"async (reqres=> {
    const id = req.params.id;

    await StudentModel.findByIdAndRemove(id).exec();
    res.send("Deleted Successfully!!!");
    console.log("Deleted Successfully!!!!");
});

*    After writing all the above code run the command 'npm run devStart' in the terminal.
*    You should see the following output in the terminal.

> server@1.0.0 devStart C:\Users\HP\Desktop\Assignments\DS Assignments\Services\Product Service\server
> nodemon app.js

[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json  
[nodemon] starting `node app.js index.js`   
Server is started and running on 3001

🔑    Step 07 - run in postman.

*    POST Method.

HTTP Method : POST
URL : https://localhost:3001/insertStudent
Body : 
{
    "studentName": "Raj",
    "studentFaculty": "IT"
}

*    GET Method

HTTP Method : POST
URL : https://localhost:3001/readAllStudents

*    GET Method - By id

HTTP Method : GET
URL : https://localhost:3001/readStudentById/<id>

*    PUT Method.

HTTP Method : PUT
URL : https://localhost:3001/updateStudent
Body : 
{
    "studentFaculty": "SE"
}

  DELETE Method - By id

HTTP Method : DELETE
URL : https://localhost:3001/deleteStudent/<id>

😊    These are the main steps involved in creating the backend with REST API and MongoDB. Hope this blog helped you to get an overview about setting up the backend in a MERN project.

[Stay tuned with the blog posts for further updates in the MERN project]. 

Sunday, May 2, 2021

Introduction to Cloud Computing

👉    The Evolution of cloud computing. 

1.    Standalone Systems 

       - The systems which are installed in the local machine to acquire the service.
       - This is in contrast with grid-computing and work remotely.
       - This software applications are not connected to the network and has the ability to operate when offline.


2.    Client - Server.

       - The software application is installed in the server.
       - Clients access the server remotely.
       - In early stage thin clients were used but with time thick clients were introduced.


3.    Web-applications.

       - Access the applications through internet to acquire the service.
       - Web clients can be thin or either thick.
       - The applications are accessed through web browser which requires an active network connection.

4.    Super Computing.

       - This is a computing process which refers to processing of massively complex or data-laden problems using the concentrated computer resources of multiple computer systems working in parallel.
       - This type is mainly used in computation heavy tasks.
    
5.    Cluster Computing.

       - This is a process where many servers are grouped to obtain one fully functional server.
       - This helps to obtain high performance and availability.
       - The servers in the cluster are linked through a LAN network.




6.    Grid Computing.

       - Combining different cluster in different locations to obtain a grid structure.
       - This is used widely used in scientific processes.
       - High performance and availability is ensured by grid computing


👉    Cloud computing. 

*    Cloud computing is an internet process which is the illusion of infinite computer resources, elimination of up-front commitment by cloud users and pay for the use as needed. [Berkeley RADLabs]

*    Cloud computing is a utility service which gives access to tech resources by an expert/experts which is available on demand.




👉    Key ideas of Cloud computing.

*    Pay as you go on. - Pay for the amount used in the cloud services.

*    Self-service interface - The interface for cloud users for monitoring and metering of cloud connection.

*    Auto-scaling    -    Allocating the resource dynamically without under-provisioning or over-provisioning.


👉    Enabling technologies of Cloud computing.

*    Virtual machines.
*    Virtual Storage.
*    Load balancing.
*    Auto-scaling.
*    Monitoring & metering.

👉    Examples of Cloud computing.

*    Amazon EC2.
*    Microsoft Azure.

👉    Virtualization in Cloud computing.

*    Virtual Machine. - Run multiple machines in one machine.

*    Virtual Storage  -  logical space to store data.

*    Virtual Network    -    SDN (Software Defined Network).


👉    Auto-scaling in Cloud computing.

*    Allocating of resources according to the need of the cloud user to avoid under-provisioning and over-provisioning.


👉    Types of cloud - based on structure.

*    Public clouds    -    Open to general public, multi-tenant, no operational or capital cost.

*    Private clouds    -    Restricted only to the owner, solo-tenant, high operational and capital cost.

*    Hybrid clouds    -    This is kind of private cloud but in case need more resource move to public cloud to store or process some insensitive data.

*    Community clouds    -    This is restricted for a specific community like the university students.



👉    Types of cloud - based on service.

*    Iaas (Infra-structure as a service)    -    Create a cloud infrastructure like the virtual machine, disk space, memory , etc.

*    Paas (Platform as a service)    -    Installing a service or application in the cloud platform and obtaining the service. Eg. Tomcat Server

*    Saas (Software as a Service)    -    Using the software in cloud to obtain the service. 
Eg. Microsoft 365.    



Monolithic vs Microservices

👉     Monolithic Architecture. *     Monolithic architecture was there before Microservices came into action.  *     All functionalities or...