How services interact with each other. Pooling / pushing. Advantages / Disadvantages. Choice

Not always a more productive solution — a solution that requires fewer resources to run — is the best. Often, concomitant factors are more significant: predictability of failure behavior, speed of recovery after failures, etc. Let's consider this on the example of interservice interaction systems.





  • The courier delivered the order. When the status of the order changes, it is necessary to notify the interested parties about these events.





  • The client sends a message to the support chat. It is necessary to notify the support services about the received data from the client.





  • . . .





/ . () .





:





- . , . ..





- "-". . , . , , ..





?





, -, . . HTTP- .





: Websocket. .





,

TCP/HTTP- . ? ? ? , ?





:









  1. ( ) HTTP (500



    , 502



    , 504



    , ..)





  2. (4xx



    )





, . , , , , , " ", . , .





, . " ?" " ".





.





:









  • 500-





500-

- X. 500- . ?





:





  1. - - (, ). .





  2. , 500. , , .





, :





  1. , (, 500-).





  2. , , , ( 500-).





  3. , ( 40x-).





, , :





  1. ?





  2. "" , ?





  3. "", - TCP- (iptables DROP



    )?





, , .





:





, , ,





:









  • ;





:









  • ,





  • : , () ,





  • TCP (iptables -j DROP



    )





  • DDoS .





:





  • , - ( : , ), .





-

, . .





- . , , ( " ") . TCP , . DDoS .





  • , -





  • , ( ), -





  • .





  • ,





  • , . , , .





, : .





( ), , - . ?





  • ,









  • TCP





  • / .





? , 1 , - 1RPS . , ( )? . , , , .





, " ; , ?". ( , ) :









  • , .





, BTREE , " ?", , . .





.





  1. . index := 0



    . index



    - , .





  2. limit



    index



    .









  3. index := index + 1











  4. 2





, , index



, .





, , ... : index



. .





? API . .





, , , . , - :





SELECT
    *
FROM
    "table"
WHERE
    "somefield" = $1
LIMIT
    100
OFFSET
    $2

      
      



, index



($2



). ( index



).





? :





SELECT
    *
FROM
    "table"
WHERE
    "id" > $1
ORDER BY
    "id"
LIMIT
    100

      
      



, index



, . :





  1. . index := 0







  2. limit



    , index







  3. index



    , id











  4. ,





  5. 2





, , ( ).





. ?













  • , , /.





  • index



    . , .





. index



state



:





  1. . state := null



    .





  2. limit



    , state







  3. , , new_state



    . state := new_state











  4. -





  5. 2





? .





  • state



    . JSON .





  • "" ( index



    , ?). , state



    .





state



, , , , . :





  1. . cursor := null, filters = _



    .





  2. limit



    , cursor



    , filters



    .





  3. , , cursor



    . cursor := response.cursor











  4. , 2





  5. -





  6. 2





, , , , , .





:





  • , . , ( ).





  • , , . .





  • - , . JSON, base64- ( ) .





. .





B



. , .





, , ( ) : , , , .





, limit , , . limit' . , id



, .





, , , ( ). , , .





, , .





, , .





.





/ . . A. B.





, .





- , "". , PostgreSQL. :





  • SERIAL/BIGSERIAL users



    , lsn



    (Last sequence number).





  • , lsn







  • lsn



    () BTREE .





:





UPDATE
   "users"
SET
   "name" = $1,
   ...
   "lsn" = DEFAULT /*  */
WHERE
   "user_id" = $21

      
      



- :





SELECT
    *
FROM
    "users"
WHERE
    "lsn" > $1
ORDER BY
    "lsn"
LIMIT
    $2

      
      



lsn



. .





  1. , , .





  2. , , TCP-





  3. /. .








All Articles