Posts

Showing posts with the label Web Architecture

[Node.js] Web Architecture Design

1) Traditional Web Application Processing Model - Multi-Threaded Request-Response Any Web Application developed without NodeJS typically follows the "Multi-Threaded Request-Response model" (or just "Request/Response Model"). This differs from the NodeJS way in that it uses multiple threads to handle concurrent client requests. Under the hood, server waits in infinite loop and creates one thread per client request. If the server gets many client requests that require long blocking I/O operations, then more threads become 'busy'. As a result, the remaining clients requests have to wait longer due to core-thread resources. 1.1) Detailed Flow Ahead of time: Web Server is in infinite loop and waiting for Client Incoming Requests. Web Server internally maintains a Limited Thread pool to provide services to Client Requests. Once threads free up in thread pool, server pick up those threads and assign them to remaining client requests. Clients send re...

[Redis] Redis Cluster

Image
1) Overview Provides better Scalability and Load Balancing - Redis Cluster allows your Redis data to be automatically sharded across multiple Redis nodes. High Availability - Cluster provides ability to continue operations when a subset of the nodes experience failures or unable to communicate with the rest of the cluster; however, large scale failures may stop the operation. 2) Data Sharding Data Sharding is a method to break up a big database into smaller parts. The reason for data sharding is that, after a certain scale point, it is cheaper and more practical to scale horizontally (by adding more machines) than to grow it vertically (by adding buffier servers or adding more CPU/ram to servers). 3) How it works? 3.1) Redis Cluster TCP ports Unlike sentinel, there is no dedicated monitoring. Instead, every cluster node have 2 TCP connections open. The first one is a standard redis TCP used to serve clients. Another is a cluster bus port (n...

[Redis] Redis Sentinel

1) Overview A system designed to help manage Redis instance. Primary purpose is to provide high availability system, by monitoring, notifying and providing instances failover. Does this by monitoring master and slave nodes. When master node is down, sentinels will coordinate to promote a slave node into master. 2)   4 main tasks 2.1) Monitoring Check if your master and slaves instances are working as expected 2.2) Notification Notify other program or system administrator via an API, when something goes wrong with the monitored instances 2.3) Automatic Failover On master failure, sentinel promotes one of the slaves to master, then make the other additional salves use the new master. 2.4) Configuration Provider Sentinel acts as source of authority for clients service delivery. Clients connect to Sentinels in order to ask for address of current Redis master responsible for given service. If a failover occurs, Sentinels will report the new add...

[Websites] Eager and Lazy Loading

[Website] Eager Loading, Lazy Loading A simple explanation is this: 1. Eager loading : you do everything when asked. Classic example is when you multiply two matrices. You do all the calculations. 2. Lazy loading : you only do a calculation when required. In the previous example, you don't do any calculations until you access an element of the result matrix. 3. Over-eager loading : this is where you try and anticipate what the user will ask for and preload it. Websites  In the context of a website, you can imagine that there are three ways the image loading could work on this page: ( eager );  Load only the displayed images on page load and load the others if/when they are required ( lazy ); and  Load only the displayed images on page load. After the page has loaded preload the other images in the background in case you need them ( over-eager ).  https://stackoverflow.com/questions/1299374/what-is-eager-loading

[Docker] Cli you cannot live without

docker ps  —  Lists running containers . Useful flags: -a / -all for all containers (default shows just running) —-quiet /-q to list just their ids (useful for when you want to get all the containers).  docker pull  — Most of your images will be created on top of a base image from the Docker Hub registry. Docker Hub contains many pre-built images that you can pull and try without needing to define and configure your own. To download a particular image , or set of images (i.e., a repository), use docker pull. docker build  — The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH or URL. Use the -t flag to label the image, for example docker build -t my_container . with the . at the end signalling to build using the currently directory. docker run  —  Run a docker container based on an image , you can follow this on with other commands, such as -it bash to then run bash from ...

[Terminal] Finding port availability and killing process using it

Image
To find out if there are any processes using a particular port, you should run the following command line: lsof -n -i4TCP:<PORT NUMBER> which will give you the following: Then, enter the following cl to kill the process: kill -9 <PID> More Info lsof: means list open files lists file information about files opened by particular process(es)ers to host names for network files.  -n option makes the command faster by preventing it from doing an IP to hostname conversion. -i[internet address] option selects the listing of files whose internet address matches the internet address.  Internet address format:  [4 or 6][protocol][@hostname | hostaddr][:service | port] The 4 or 6 refers to IPv4 and IPv6 Resources: https://stackoverflow.com/questions/3855127/find-and-kill-process-locking-port-3000-on-mac

[Java] Servlets

A servlet is a class which responds to a particular type of network request (most commonly an HTTP request). Servlets are usually used to implement web applications. Servlets run in a servlet container, which handles the network side (eg. parsing HTTP request, connection handling.etc). One of the best-known source servlet containers is Tomcat. Flow of Request Client sends HTTP request to Web Server Web Server forwards HTTP request to Web Container Web Container converts request into valid request object (because servlet cannot understand HTTP; only understands objects) Web container spins a thread for each request. All the business logic goes inside doGet() and doPost() methods inside the servlets. Servlet builds a Java response object and sends it to the container. It converts that to HTTP response again and send it to the client.

[Front End] Client-side rendering vs Server-side rendering

Do you ever wonder - what can a website not do? You can chat, play games, work on Google Doc.etc.  Server-Side Rendering Traditional way of rendering a website. How it works? Server generates HTML files and sends it to browser (client), where it is displayed as a website. Doesn't matter if new page has one difference than the current page, the browser will ask for the entire page, and re-render everything. Client-Side Rendering Didn't become popular until JavaScript libraries started using this development style; examples are Vue.js and React.js How it works? Instead of getting the generated HTML files from the server, you download the data you need, template HTML(s) and Javascript (libraries). Then, the browser renders the data into the template HTML using Javascript or Javascript Libraries. Server is responsible for less processing (doesn't need to generate the HTML) - this responsibility is pushed to the client (browser). When navigating through ...

[Web Architecture] Reverse Proxy vs Load Balancing

According to nginx.com, the definition of Reverse Proxy and Load Balancer are: A  reverse proxy  accepts a request from a client, forwards it to a server that can fulfill it, and returns the server’s response to the client. A  load balancer  distributes incoming client requests among a group of servers, in each case returning the response from the selected server to the appropriate client At this point, it almost seems as if they are the same thing. Let's dive deeper to see the difference. Load Balancing Sometimes, the volume of requests generated from your website may be too much for one server to handle. In that case, you will use  multiple servers. But even then, you will need something to distribute the requests to each server; evenly. This 'something' is the load balancer .  They basically solve network traffic problems. Session Persistence A cool thing that I also read about is session persistence . Will need more researching for this.....