Solutions to common problems of backend services

1 Token generated
  token = md5(uid+timestamp+nance)
  is stored in redis, and different valid time is set according to the business.

2 Message legality (tamper-proof)
  digital signature
  eg

  req:{
    uid int
    param1 int 
    param2 int
    sig string
  }

  sig = md5(uid+param1+param2+token)

  See also:
    kong plugin hmac-auth

3 Idempotent
  scheme 1: 
    If the business support has a unique message ID and can be persisted, it should be queried first.
    Depending on the business, a pessimistic or optimistic way of executing the business can be considered.
  Solution 2: 
    Use the signature of 2, token+sig is stored in redis. The effective time is set according to the business.
    This solution is not completely idempotent, and whether to use it is judged according to functional requirements and performance requirements.

4 Request Tracking
  There are many http business request tracking tools. zipkin, jeager, etc.
  For custom protocols such as tcp, refer to the solution of zipkin.
  When a user connects once, a spanid is generated.
 

Guess you like

Origin blog.csdn.net/weixin_56766616/article/details/121910581