Im – system architecture design

Time:2022-5-9

1. General

The architecture design of IM system is shown in the following figure, which is mainly divided into two parts:

  • Cloud disk system cpan (blue part). In order to be compatible with the existing cloud disk system, theWeb SMandIM PortalReceive IM requests from cloud disk users, includingMessagingFriends listetc.
  • Instant messaging system im (yellow part). Support the user im requirements of desktop and mobile terminals, includingLogin and logoutmail listPersonal CenterMessaging and searchgroup management etc.

This paper focuses onInstant messaging IMSystem design, including design ideas, functions of each module, introduction to main processes and FAQs.

Im - system architecture design

im-architecture.jpg

2. System design

Im - system architecture design

im-architecture-c4model.jpg

2.1. System objectives

Enterprise instant messaging system, inImprove the efficiency of team communication and cooperationOn the basis ofInterconnection of all thingsscene

  • Team communication and cooperation, related functions include: instant messaging, cloud disk, multi person meeting, schedule management, task management, etc
  • All things are interconnected, and relevant functions include: tripartite system assistant, webhook support and public robot

2.2. Design ideas

  • Microservice architectureTo ensure the two-way expansion of services and better disaster tolerance
  • Control signalingAndStream dataSeparation, better guaranteeControl signalingHigh availability of, andStream dataImmediacy of
  • Message busTo better ensure the of microservicesHigh cohesionandLow couplingFeatures, realizablesynchronizationorasynchronousBusiness data flow
  • Database read-write separation, in-depth analysis of business needs and rational designdatabase modelTo achieve the separation of reading and writing as much as possible,Try not to use database transactions
  • Service idempotent, horizontal expansion of business level

3. Module introduction

Im - system architecture design

im-context.png

3.1. Portal

location

  • The first entry of IM user, communication protocol grpc
  • Reverse proxy passport, account, group, search, robot and other micro service modules

function

  • Realize user session retention, instead of carrying a token every request
  • Realize the unified standardization of request / response, so that the protocol format is clear and maintainable
  • To realize a complex business flow, such as a user’s request, it may need to be disassembled into multiple background requests, which are completed by different microservices
  • Support configurable background microservice address
  • It supports idempotent and can be expanded horizontally

3.2. Passport

location

  • SSO (single sign on) service realizes the unified login authentication of all systems, supports multiple login methods, and outputs JWT

function

  • Registration function, supportForm registration(including mobile phone number verification and email verification), andInterface with existing account system
  • Login function, supportAccount loginQR code loginMobile number loginAnd other login methods
  • Logout function, support one clickWhole systemLog out (save the callback of the business system)
  • currentorhistoryLogin operation view, including login equipment, login time, login method, login IP and other information
  • Support RBAC model (role-based access control)
  • It supports idempotent and can be expanded horizontally
  • Support crud operation of basic account information, including name, mobile phone number, email, job number, date of birth, gender, etc

3.3. Account

location

  • Proprietary information management of IM account

function

  • Support crud operation of IM system proprietary information, including user team organizational structure, friend information, andIM SettingRelevant information, such as skin, page layout, etc
  • Support IM user accessAvailable SM addressesList, the routing policy can be based onOffice location nearbyTeam default SMOther factors judgment
  • It supports idempotent and can be expanded horizontally

3.4. Search

location

  • Retrieval of historical messages

function

  • The message search function can filter based on date, group, sender, receiver and message keywords, and supports paging and sorting
  • It supports idempotent and can be expanded horizontally

3.5. Group

location

  • group management

function

  • Group creation and dissolution
  • Group modification function, including modifying name, announcement and administrator
  • Group invites and removes members. When inviting, new people can view the latest n records
  • Group exit and topping function
  • The group silence function can silence only robot messages or all robot messages
  • It supports idempotent and can be expanded horizontally

3.6. Robot

location

  • supportPeople and thingsThings and thingsInternet, herematter, which can refer to a software system, an IOT device, etc

function

  • Add common third-party robots based on groups, such as sentry, Prometheus, gitlab, etc
  • Based on group, it supports user-defined robots and completes message notification through webhook
  • Support adding public robots as friends, such as punch in notification, weather reminder, schedule management, etc
  • It supports idempotent and can be expanded horizontally

3.7. Storage

location

  • Support object storage

function

  • Upload and display of pictures. The display parameters can support watermark, scaling of specified proportion, artificial intelligence recognition, etc
  • File upload and download, support upload progress and download progress
  • Permission verification of image display and file download
  • Regular cleaning function, save for the last 3 months, or 1g at most
  • It supports idempotent and can be expanded horizontally

3.8. Router

location

  • Broker maintainer

function

  • Provide API to implement brokerService discoveryFunctions, including registration, logout, and callback of the currently online broker to notify its newly online broker information
  • maintainOnline user routing table, i.eOnlineUserId(OnlineGroupId)AndBrokerThe corresponding relationship of (user online / offline information, which is actively sent to the router by each broker)
  • WhenOnline user routing tableNotify each broker when changes occur
  • It supports idempotent and can be expanded horizontally

3.9. SM (Session Manager)

location

  • Second entry for IM users, communication protocol grpc
  • maintainIM system and usersoffull duplexTCP channel

function

  • The creation, maintenance, use and destruction of full duplex TCP channels for IM users, among which maintenance can adoptTimed heartbeat
  • The sending and receiving of IM messages need to be guaranteedFour features of IM messages
  • recordList of current online users
  • Each time you start and exit, you need to complete the registration and logout in the account service, which can be realized through redis
  • It supports idempotent and can be expanded horizontally

3.10. MQ

location

  • Message bus to realize low coupling and two-way scalability of various micro services

function

  • The message is successfully delivered after MQ completes persistence
  • For the safe consumption of messages, only when the message is processed successfully and the next service is taken over clearly can it be regarded as safe consumption

3.11. Recorder

location

  • Message recorder

function

  • Monitor all messages of IM system and complete message warehousing
  • It supports idempotent and can be expanded horizontally

3.12. Auditor

location

  • Message auditor

function

  • Audit content: whether the message content is legal and does not contain semantics such as anti party, treason, pornography, gambling and drugs
  • Audit device: the mobile device cannot receive files
  • Message authentication: verify whether the sender and receiver are friends (or colleagues), whether the sender is a group member, etc
  • It supports idempotent and can be expanded horizontally

4. Summary

Combined with the mainstream requirements of IM, this paper expounds the IM system architecture. From the macro level, I hope you have a preliminary understanding.

Next, this topic will introduce the implementation logic of core functions in depth. (please sit down and help me)