Goal
Performance
High performance is a must, for startups, non-stop piling machines are also a relatively large cost, can save the province.
Resource Split Isolation
Splitting a resource requires that each service provide a corresponding interface, and the service cannot directly access the database or cache of other services.
Highly Available
The tentative target is 99.9 availability.
Development language
Since our new project has no historical burden, all modules are re-developed, so we are free to choose the development language and development framework. Previously our project back-end development language was miscellaneous, there were Golang projects, PHP projects, and a small part of the Nodejs project. New project I decided to unify the background development language, choose Golang as our main back-end development language. Golang has the following advantages in our main:
- Golang has a good balance in performance and development efficiency, is simple in syntax, simple and efficient in concurrent programming, and has a sound base library.
- Bring some Pprof package can profile the current program's CPU consumption, memory consumption, lock status, channel blocking, etc., it is very convenient for us to locate the problem.
- For PHP programmers, it's easier to get started, and the performance is much better.
Service Framework
For average small and medium-sized startups, it is relatively costly to develop a micro-service framework ( Local tyrants company has a bunch of idlers except ).
After comparison, we use Go micro as the development framework, because it contains almost all of the microservices components, and support very good extensibility, through the interface design, let us expand some of our own components, such as service discovery, transport protocol, Configuration center and so on.
Go Micro is a plug-in architecture that focuses on providing the underlying interface definitions and underlying tools that can accommodate a variety of implementations.
For example, the following is a registry interface:
type Registry interface { Register(*Service, ...RegisterOption) error Deregister(*Service) error GetService(string) ([]*Service, error) ListServices() ([]*Service, error) Watch(...WatchOption) (Watcher, error) String() string Options() Options}
The registry interface defines the interface for service discovery, which uses consul as the implementation of service discovery by default, but can also be used with other implementations such as ETCD and zookeeper, as long as the interface can be satisfied. The plug-in architecture means that if you want to replace the underlying implementation, you don't need to modify any of the underlying code.
Micro-framework.png
Go Micro is mainly composed of the following components:
Registry
Provide service registration, discovery, logoff, monitoring mechanism, the registry is consul by default, can be used in the form of plug-in support ETCD2/3, zookeeper, etc.
Selector
The selector provides load balancing, filtering the microservices through the filtering method, and selecting microservices through different routing algorithms.
Transport
Micro-Service synchronization request/Response communication mode, such as HTTP, Grpc, TCP, UDP, etc.
Broker
Micro-service key asynchronous publish/Subscribe communication mode, better deal with distributed system decoupling problem, by default HTTP mode, production environment will usually use message middleware, such as Kafka, NSQ and so on.
Codec
Inter-service message encoding and decoding, support JSON, PROTOBUF, Bson, Msgpack and so on.
Server
Used to start the service, name the service, register handler, add middleware, and so on.
Client
Provides a microservices client.
We will develop two times based on Go micro, expand some of our own components, such as configuration center, log collection, APM call chain, monitoring data collection and so on.
( not to be continued)
My public number.
Qrcode_for_gh_e51d4037d8fa_430.jpg