Server - Database


Shared Hosting: Multiple Web Site in a single server which is the functionality of web server application, uses different http folder for each site.

Virtual Private server: Web Server is differnent for each web app with own OS. Single Machine has can have multiple OS through virtualization or may have different Machine which is connected with a Proxy server. Proxy server decides which request forward to which machine or which vm machine same.

Load Balancing:
A load balancing setup includes a load-balancing virtual server and multiple load-balanced application servers. The virtual server receives incoming client requests, uses the load balancing algorithm to select an application server, and forwards the requests to the selected application server.





Concurrent Request

This is configurable by selecting multi-process or mutli-thread. where number of max thread can be selected. After reaching that max number of thread, new process will be created. Also, queue mechanism can be selected, so requests will be processed serially, fake concurrency. So this depends on the server functionalities and what is configured. 


Distributed Transaction

A distributed transaction is a transaction that works across several computers. Say you start a transaction in some method in a program on computer A. You then make some changes to data in the method on computer A, and afterwords the method calls a web service on computer B. The web service method on computer B fails and rolls the transaction back. Since the transaction is distributed, this means that any changes made on computer A also need to be rolled back.



Distributed vs Cloud

Distributed computing just means I break up a problem so that I can have a whole bunch of computers work on it at the same time. Distributed computing involves dividing a large problem into smaller slices and having multiple networked computers process the slices.

Cloud computing usually refers to providing a service via the internet. That service can be pretty much anything, from business software that is accessed via the web to off-site storage or computing resources. The term cloud computing has become a marketing term that has come to represent almost anything. To coders, the term refers to a distributed way of storing and retrieving name/value pairs. 

Database Replication
Database replication can be used on many database management systems, usually with a master/slave relationship between the original and the copies. The master logs the updates, which then ripple through to the slaves. The slave outputs a message stating that it has received the update successfully, thus allowing the sending (and potentially re-sending until successfully applied) of subsequent updates.
Multi-master replication, where updates can be submitted to any database node, and then ripple through to other servers, is often desired, but introduces substantially increased costs and complexity which may make it impractical in some situations. The most common challenge that exists in multi-master replication is transactional conflict prevention or resolution.

Database  Partitioning
Each partition may be spread over multiple nodes, and users at the node can perform local transactions on the partition. This increases performance for sites that have regular transactions involving certain views of data, whilst maintaining availability and security.
Horizontal partitioning involves putting different rows into different tables. Vertical partitioning involves creating tables with fewer columns and using additional tables to store the remaining columns.

There are many techniques to scale a relational database: master-slave replicationmaster-master replicationfederationshardingdenormalization, and SQL tuning.
MySQL

Mysql keeps table structure info in a file and contents in another file for each table. And this also depends on Memory Storage Engine.

Creating an index on a field in a table creates another data structure which holds the field value, and a pointer to the record it relates to. This index structure is then sorted, allowing Binary Searches to be performed on it. 

The downside to indexing is that these indexes require additional space on the disk since the indexes are stored together in a table using the MyISAM engine. 

Most MySQL indexes (PRIMARY KEYUNIQUEINDEX, and FULLTEXT) are stored in B-trees. Exceptions: Indexes on spatial data types use R-trees; MEMORY tables also support hash indexesInnoDB uses inverted lists for FULLTEXT indexes.

ACID


Master-slave replication


The master serves reads and writes, replicating writes to one or more slaves, which serve only reads. Slaves can also replicate to additional slaves in a tree-like fashion. If the master goes offline, the system can continue to operate in read-only mode until a slave is promoted to a master or a new master is provisioned.

Master-master replication

Both masters serve reads and writes and coordinate with each other on writes. If either master goes down, the system can continue to operate with both reads and writes.
  • You'll need a load balancer or you'll need to make changes to your application logic to determine where to write.
  • Most master-master systems are either loosely consistent (violating ACID) or have increased write latency due to synchronization.
Federation
Federation (or functional partitioning) splits up databases by function. For example, instead of a single, monolithic database, you could have three databases: forumsusers, and products. 
  • You'll need to update your application logic to determine which database to read and write.
Sharding/Horizontal Partitioning

Sharding distributes data across different databases such that each database can only manage a subset of the data. Taking a users database as an example, as the number of users increases, more shards are added to the cluster.

SQL 

  • Strict schema
  • Relational data
  • Lookups by index are very fast
NoSQL


  • Dynamic or flexible schema
  • Non-relational data
NoSQL is a database system which doesn't use string based SQL queries to fetch data. Instead you build queries using an API they will provide. It dont have any schema so table configuration is dynamic.

BASE is often used to describe the properties of NoSQL databases. In comparison with the CAP Theorem, BASE chooses availability over consistency.


KeyValue Store
A key-value store generally allows for O(1) reads and writes and is often backed by memory or SSD. A key-value store is the basis for more complex systems such as a document store, and in some cases, a graph database.


Wide Column Store

Cassandra, Hadoop, BigTable(pioneer of NoSQL, Google)



Document Store


MongoDB


Graph Databases

BigData

Cache

Web server caching

Web servers can also cache requests, returning responses without having to contact application servers.


Database caching

Your database usually includes some level of caching in a default configuration, optimized for a generic use case. 

Application caching


Caching at the database query level

Whenever you query the database, hash the query as a key and store the result to the cache.

Caching at the object level

See your data as an object, similar to what you do with your application code. Have your application assemble the dataset from the database into a class instance or a data structure

Remote procedure call (RPC)

In an RPC, a client causes a procedure to execute on a different address space, usually a remote server. The procedure is coded as if it were a local procedure call, abstracting away the details of how to communicate with the server from the client program.

Representational state transfer (REST)

REST is an architectural style enforcing a client/server model where the client acts on a set of resources managed by the server. The server provides a representation of resources and actions that can either manipulate or get a new representation of resources. All communication must be stateless and cacheable.

Stateless: there is no specific way to log out

Message authentication code

Again, stateless means without state. But, how can we identify a user from a token without having any state on the server? Surprisingly, it’s very easy! just send all the data to the client.
So what would you store/send (send to client/network)? The most trivial example is an access token. Access tokens usually have a unique ID, an expiration date and the ID of the client that created it. To store this, you would just put this data into a JSON object, and encode it using base64.
Now, having a self-contained token, you will need to make sure that nobody can manipulate the data. For this you should sign it using MAC algorithm or any other digital signature method available.

POST vs PUT vs GET

https://stackoverflow.com/questions/630453/put-vs-post-in-rest


HTTP vs HTTPS

https://security.stackexchange.com/questions/8145/does-https-prevent-man-in-the-middle-attacks-by-proxy-server
https://security.stackexchange.com/questions/5126/whats-the-difference-between-ssl-tls-and-https



https://scotch.io/tutorials/the-ins-and-outs-of-token-based-authentication
https://kaleidos.net/blog/295/stateless-authentication-with-api-rest/
https://auth0.com/blog/stateless-auth-for-stateful-minds/
https://nordicapis.com/defining-stateful-vs-stateless-web-services/

Comments

Popular posts from this blog

Thread & Locks

Opengl-es Buffer

Kernel Startup