Write an IM like WeChat from scratch with t-io (05): Architecture Design

About the architecture


The commander is incompetent and exhausts the three armies; the structure is not good, and the programmer is exhausted.
The architecture is the software, and the foundation is the building.
If the foundation is rotten, the building will collapse, and if the structure is rotten, the software will fail.


Architecture diagram

Architecture explanation

1. Multi-level cache

Two-level is a process that is used more. The so-called two-level cache refers to the local cache and the distributed cache. When the local cache misses a hit, the data is obtained from the distributed cache; and this architecture talks about multi-level cache. The local cache is divided into the cache before the interceptor and the business data cache. The cache before the interceptor means that when a request is received, the cache is directly obtained from the request path, and if it is hit, it will be returned directly; the business data cache is relatively popular, and this article skips the introduction

2. Protocol adaptation/conversion


For web-based clients, websocket is more natural and comfortable; for non-web-based clients, such as Android and IOS, ordinary sockets are more comfortable and simple. Therefore, the server needs to support both normal socket and websocket. In order to simplify business development and unify the message body structure, this architecture has specially placed protocol adapters and protocol converters to unify packets of different protocols into packets required by business. Fortunately, t-io has a built-in protocol converter and also provides a mechanism for port data sharing, so it becomes relatively simple to implement the intent of this architecture.

3. Flow Control

Flow control is an indispensable function of every system. Don't use more words, it is not complicated to implement

4. Task queue

In order to improve the fluency of the system, many operations will become asynchronous, and the queue becomes an essential component

5. t-io cluster


The cluster version of the t-io enterprise version has built-in cluster capabilities and is quite simple to use. This system has a cluster switch that can switch between cluster and non-cluster at any time

Next episode preview

Use t-io to write an IM like WeChat from scratch (06): IM cluster design


Guess you like

Origin blog.51cto.com/15006109/2582538