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- . ? ? ? , ?
:
-
( ) 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-
/. .