Cómo interactúan los servicios entre sí. Agrupar / empujar. Ventajas desventajas. Elección

No siempre una solución más productiva, una solución que requiere menos recursos para ejecutarse, es la mejor. A menudo, los factores concomitantes son más importantes: predictibilidad del comportamiento de falla, velocidad de recuperación después de fallas, etc. Consideremos esto en el ejemplo de los sistemas de interacción entre servicios.





  • El mensajero entregó el pedido. Cuando el estado del pedido cambia, es necesario notificar a los interesados ​​sobre estos eventos.





  • El cliente envía un mensaje al chat de soporte. Es necesario notificar a los servicios de soporte de los datos recibidos del cliente.





  • . . .





/ . () .





:





- . , . ..





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





?





, -, . . 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