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- . ? ? ? , ?
:
-
( ) HTTP (
500
,502
,504
, ..)
(
4xx
)
, . , , , , , " ", . , .
, . " ?" " ".
.
:
-
500-
500-
- X. 500- . ?
:
- - (, ). .
, 500. , , .
, :
, (, 500-).
, , , ( 500-).
, ( 40x-).
, , :
?
"" , ?
"", - TCP- (
iptables DROP
)?
, , .
:
, , ,
:
;
:
,
: , () ,
TCP (
iptables -j DROP
)
DDoS .
:
, - ( : , ), .
-
, . .
- . , , ( " ") . TCP , . DDoS .
, -
, ( ), -
.
,
, . , , .
, : .
( ), , - . ?
,
TCP
/ .
? , 1 , - 1RPS . , ( )? . , , , .
, " ; , ?". ( , ) :
, .
, BTREE , " ?", , . .
.
.
index := 0
.index
- , .
limit
index
.
index := index + 1
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
, . :
.
index := 0
limit
,index
index
,id
,
2
, , ( ).
. ?
, , /.
index
. , .
. index
state
:
.
state := null
.
limit
,state
, ,
new_state
.state := new_state
-
2
? .
state
. JSON .
"" (
index
, ?). ,state
.
state
, , , , . :
.
cursor := null, filters = _
.
limit
,cursor
,filters
.
, ,
cursor
.cursor := response.cursor
, 2
-
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
. .
, , .
, , TCP-
/. .