Micro Services Architecture Case (03): Introduction to database selection, business planning and design data

Update progress (section 6 total):

01: Introduction to Project technology selection, architecture illustration

02: business architecture design, hierarchical management system

03: Database selection, design and planning business data

First, select the database

1, the database classification

Database Type Common Database
Relational MySQL、Oracle、DB2、SQLServer等。
Non-relational Hbase、Redis、MongodDB等。
Line storage MySQL、Oracle、DB2、SQLServer等。
Columnar storage Hbase、ClickHouse等。
Distributed Storage Cassandra、Hbase、MongodDB等。
Key-value store Memcached、Redis、MemcacheDB等。
Graphics memory Neo4J, TigerGraph 等.
Document storage MongoDB、CouchDB等。

2, database selection

Based on the specific application environment, select the most suitable database, set up a data storage mode so that it can efficiently store data to meet the application needs of various users. For example: general business library, select the amount of data is not the case MySQL; frequent search operations, you can use ElasticSearch; there are a lot of hot data system, you can use a common database cache.

3, micro-services database

A key point is that the micro-service architecture database design and planning, the basic principle is that each service has its own separate database, and only micro services themselves can access the database. If you want to access other services, can only be operated by the service provide external call interface, which can compress the database interface to operate on troubleshooting and performance optimization can provide support, which would also make the system more structured framework. This mode is illustrated as follows:

C by micro-micro-services database operation the service A A, B, or by micro-services database operation B.

Second, the business planning database

1, the overall division

Three main data storage: MySQL (divided into three business library), ElasticSearch (single), Redis (single).

2, user library

user- Data: storing user related data structures: User information such as, Token, operation log .

CREATE TABLE `hc_user_base` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  `user_name` varchar(50) DEFAULT NULL COMMENT '用户名',
  `pass_word` varchar(300) DEFAULT NULL COMMENT '加密密码',
  `phone` varchar(30) DEFAULT NULL COMMENT '手机号',
  `email` varchar(50) DEFAULT NULL COMMENT '邮箱',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `state` int(1) DEFAULT '0' COMMENT '状态:0可用,1禁用',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表';

3, library management system

admin- the Data: storage backend database support micro service management system, such as timers, administrator privileges, configure the dictionaries .

-- 管理员列表
CREATE TABLE `hc_admin_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  `user_name` varchar(50) DEFAULT NULL COMMENT '用户名',
  `pass_word` varchar(300) DEFAULT NULL COMMENT '加密密码',
  `phone` varchar(30) DEFAULT NULL COMMENT '手机号',
  `email` varchar(50) DEFAULT NULL COMMENT '邮箱',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `state` int(1) DEFAULT '0' COMMENT '状态:0可用,1禁用',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='管理用户表';

-- 角色和权限列表
CREATE TABLE `hc_role_info` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `role_name` varchar(64) DEFAULT NULL COMMENT '角色名称',
  `role_auth` varchar(64) DEFAULT NULL COMMENT '角色权限',
  `create_time` datetime DEFAULT NULL COMMENT '添加时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统角色表';

-- 定时器列表
CREATE TABLE `schedule_job` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '任务id',
  `bean_name` varchar(200) DEFAULT NULL COMMENT 'spring bean名称',
  `params` varchar(2000) DEFAULT NULL COMMENT '参数',
  `cron_expression` varchar(100) DEFAULT NULL COMMENT 'cron表达式',
  `status` tinyint(4) DEFAULT NULL COMMENT '任务状态  0:正常  1:暂停',
  `remark` varchar(255) DEFAULT NULL COMMENT '备注',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='定时任务';

4, data analysis library

Report- the Data: Data stored in the archive reporting, analysis results, etc., demonstrate the major cases the user's search behavior was analyzed, stored in the Report Library .

-- 书籍搜索记录
CREATE TABLE `hc_search_book` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `user_id` int(11) DEFAULT NULL COMMENT '用户ID',
  `book_id` int(11) DEFAULT NULL COMMENT '书籍ID',
  `book_name` varchar(100) DEFAULT NULL COMMENT '书籍名称',
  `search_time` datetime DEFAULT NULL COMMENT '搜索时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COMMENT='书籍被搜索记录';

-- 关键词搜索记录
CREATE TABLE `hc_search_key_word` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `user_id` int(11) DEFAULT NULL COMMENT '用户ID',
  `key_word` varchar(50) DEFAULT NULL COMMENT '关键词',
  `search_num` int(11) DEFAULT NULL COMMENT '搜索次数',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='关键词搜索记录';

5, search engine library

ES- the Data: store user search data can be imported into the ES real-time services based on MySQL dynamic library .

-- 书籍搜索信息表
CREATE TABLE `hc_book_info` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `book_name` varchar(100) DEFAULT NULL COMMENT '书籍名称',
  `book_author` varchar(100) NOT NULL DEFAULT '0' COMMENT '作者',
  `book_desc` varchar(200) DEFAULT NULL COMMENT '简介',
  `book_press` varchar(100) NOT NULL DEFAULT '0' COMMENT '出版社',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `state` int(1) DEFAULT '0' COMMENT '状态:0可用,1删除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='书籍信息表';

Third, Database Design Summary

Database design is a core point micro-service design, the basic principle is that each service has its own micro separate database, and only micro services themselves can access the database. In the micro-service architecture, database design must first meet the needs of users, ease of maintenance and expansion, have a good read and write performance, can also help developers understand and manage the system.

Fourth, the source address

GitHub·地址
https://github.com/cicadasmile/husky-spring-cloud
GitEE·地址
https://gitee.com/cicadasmile/husky-spring-cloud

Guess you like

Origin www.cnblogs.com/cicada-smile/p/11780727.html