An overview of the

  • preface
  • What are microservices
  • Features and advantages of microservices
  • The lack of microservices
  • Micro-service communication mode
  • Should I use microservices?
  • Afterword.

preface

More than half a year ago, I first heard of the word [micro-services]. Out of curiosity, I googled the word, and from then on, I have a heart to learn micro-services. In the first half of the year, because I was busy, I could not spare a complete chunk of time to learn micro-services. But all use idle time to look at related concepts and architectures. It’s been a while now, and I don’t think it’s any use just looking at the concept. You have to put it into practice to really learn something. That’s where this article (a series to follow) comes in.

What are microservices

Let’s take wechat as an example to explain micro services. First of all, suppose you want to make a simplified version of wechat product, which only has the following functions. Your initial system design should look like this:

With the migration of time, our day came to 2019.01.01 00:00 New Year, at this moment, many people are sending circle of friends. “Moments of friends” interface traffic is very, very, very large, the peak server access to the peak, then we can start to do cluster operations. That is, the entire server does cluster operations. So our login interface, payment interface, chat interface also have a replication set, at this moment these several interfaces are relatively weak, ** then we can only make the interface of the circle of friends cluster? ** The answer is yes, take a look at the figure below – microservices Architecture

So, can we unify all microservices?

Of course, the above example diagram is only a small demonstration, in real use, it is much more complicated than this, here is just to throw out the concept for you to understand.

Wikipedia defines microservices as follows:

Microservices is a style of software architecture that modular large complex applications based on Small Building Blocks that focus on a single responsibility and function. Functional blocks communicate with each other using a language-independent /Language agnostic SET of apis.

Features and advantages of microservices

Features of microservices:

  1. Single responsibility;
  2. Lightweight communication;
  3. Isolation, running in their own processes without interfering with each other;
  4. Have their own data, data independence, each microservice has its own database;
  5. Diversity of technology, choosing the right technology to do the right thing;

A micro service is responsible for a certain responsibility, just like the service of moments of friends, it is only responsible for the [add, delete and check] function of moments of friends, separate from other services

Advantages of microservices:

  • Independence Each microservice is built, deployed, expanded, scaled, and database independently. Supplementary effects when database tables are modified.
  • Agility has a single function and can quickly add new requirements
  • The flexible technology stack can take advantage of different languages, such as Python to crawl data and NodeJS to handle IO streams
  • High performance teams can be distributed to different teams for development

The lack of microservices

  1. Extra work;
  2. Data consistency;
  3. Communication cost;

Additional work is required, such as service unassembly (how to unbundle microservices and which services should be unbundled together), service registration, service discovery, communication between microservices. Each microservice holds an independent database, which cannot achieve strong data consistency but only final result consistency. Doing microservices can also increase the team’s communication costs.

Micro-service communication mode

Microservices can communicate with other microservices using two basic messaging patterns, synchronous and asynchronous messaging.

  1. Synchronous communication. In this mode, one service invokes an API exposed by another service using a protocol such as HTTP or a Remote Procedure Call (RPC) framework. This option is called synchronous messaging mode because the caller waits for a response from the receiver. Common RPC frameworks include: gRPC (Google), Thrift (Apache)

  2. Asynchronous messaging. In this mode, a service can send a message without waiting for a response, and then one or more services can process the message asynchronously. The most popular message queues are: RabbitMQ, ZeroMQ, Kafka, ActiveMQ. This article is just an introduction to how microservices communicate.

Should we use microservices?

Microservices have become a hot architecture mode, almost every major technology website is not without microservices. But are microservices really appropriate for our current user size and company level? There is no unified answer to this question. In my opinion, in fact, most small companies do not use microservices, because its disadvantages far outweigh its advantages. Single application optimization, database read-write separation, clustering, load balancing, can cope with daily traffic. When you do all the above optimization, or can not withstand the pressure, you can consider micro services. Of course, the selection of service architecture depends on different situations and the will of the company. If it is necessary to do cross-language and other requirements, then do micro services.

Afterword.

Finally, business reasons aside, we as technologists also need to learn about microservices-related technologies, not just when we don’t use them. In the current environment, there is no harm in storing more knowledge and improving their competitiveness. Personal knowledge reserve is always limited, if there is a mistake, also ask the big guy to correct. Click to read the original article and link to my Zhihu, where I will correct the mistakes in the article.

This article was first published on the public account “Zone7”. Follow the public account for the latest tweets.