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

Mysql Replication

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 and therefore does not require working with log files or positions within these files, which greatly simplifies many common replication tasks. Replication using GTIDs guarantees consistency between master and slave as long as all transactions committed on the master have also been applied on the slave.

Types of synchronizations in replication:

1.Synchronous replication : Writes are performed on both master as well as slaves simultaneously ; it is used for highly available applications

2. Asynchronous replication : In this type of replications writes are performed on master and slave syncs with the master asynchronously.

3.Semisynchronous replication : In this type of replication a commit performed on the master blocks before returning to the session that performed the transaction until at least one slave acknowledges that it has received and logged the events for the transaction.

Types of replication formats:

1.Statement Based Replication (SBR), which replicates entire SQL statements
2.Row Based Replication (RBR), which replicates only the changed rows.

Binary Log File Based Replication

  • The master writes the updates and changes into a binary log file as events from which all the slaves read these events and perform these changes in their own local database.
  • Each slave keeps a record of the binary log coordinates: the file name and position within the file that it has read and processed from the master. This means that multiple slaves can be connected to the master and executing different parts of the same binary log without affecting the operation of the master in any way.
  • Each server within a replication topology must be configured with a unique server ID. This server ID is used to identify individual servers within the replication topology, and must be a positive integer between 1 and (2^32)−1.
  • Each slave must have a unique nonzero server-id value that differs from that of the master and from any of the other slaves.
  • Each slave connects to the master using a MySQL user name and password, so there must be a user account on the master that the slave can use to connect. The user name is specified by the MASTER_USER option on the CHANGE MASTER TO command when you set up a replication slave. 
  • Any account can be used for this operation, providing it has been granted the REPLICATION SLAVE privilege.
  • Run below commands if you want to create a new user for replication purpose on the master:
    mysql> CREATE USER 'repl'@'%.example.com' IDENTIFIED BY 'password';
    mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.example.com';

Comments

Popular posts from this blog

Guice Tutorial

Introduction to Kafka

Ruby Syntax Cheat Sheet