From 4cf49ba50b2b99ab82e9b46e7666118291c5b05e Mon Sep 17 00:00:00 2001 From: "steinkirch.eth, phd" Date: Sat, 15 Jul 2023 12:36:39 -0700 Subject: [PATCH] add fundamentals of backend engineering and protocols --- README.md | 40 +++++++++++---------- code/protocol_demos/sync-async/async.js | 7 ++++ code/protocol_demos/sync-async/file.txt | 1 + code/protocol_demos/sync-async/package.json | 12 +++++++ code/protocol_demos/sync-async/sync.js | 10 ++++++ communication/README.md | 34 +++++++++++++++++- 6 files changed, 84 insertions(+), 20 deletions(-) create mode 100644 code/protocol_demos/sync-async/async.js create mode 100644 code/protocol_demos/sync-async/file.txt create mode 100644 code/protocol_demos/sync-async/package.json create mode 100644 code/protocol_demos/sync-async/sync.js diff --git a/README.md b/README.md index 46e3e56..32f92f9 100755 --- a/README.md +++ b/README.md @@ -13,21 +13,35 @@
-* **[communication](communication/)** +* **[communication patterns](communication/)** * Request Response model * Synchronous vs. Asynchronous workloads * Push * Polling and Long Polling - * Server Sent Events - * Publish Subscribe (Pub/Sub) + * Server-Sent Events + * Publish-Subscribe (Pub/Sub) * Multiplexing vs. Demultiplexing * Stateful vs. Stateless * Sidecar Pattern
+* **[execution patterns](execution/)** + * backend execution patterns + * the process, the thread, the cpu time + * reading and sending socket data + * the listener, the acceptor, the reader + * single listener, acceptor, and reader thread execution pattern + * single listener, acceptor, and multiple readers thread execution pattern + * single listener, acceptor, readers with message load-balancing execution pattern + * multiple accepter threads on a single socket execution pattern + * multiple listeners, acceptors, and reader with socket-sharding execution pattern + * backend idempotency + * nagle's algorithm + +
+ * **[protocols](protocols/)** - * protocol properties * protocol properties * OSI model * internet protocol @@ -41,8 +55,10 @@ * gRPC * WebRTC +
+ * **[HTTP](https/)** * https communication * https over TCP with TLS 1.2 @@ -54,21 +70,6 @@
-* **[execution](execution/)** - * backend execution patterns - * the process, the thread, the cpu time - * reading and sending socket data - * the listener, the acceptor, the reader - * single listener, acceptor, and reader thread execution pattern - * single listener, acceptor, and multiple readers thread execution pattern - * single listener, acceptor, reader with message load balancing execution pattern - * multiple accepter threads on a single socket execution pattern - * multiple listeners, acceptors, and reader with socket sharding execution pattern - * backend idempotency - * nagle's algorithm - -
- * **[proxy and load balance](proxy_and_lb)** * proxy vs. reverse proxy * Layer 4 vs. Layer 7 load balancers @@ -91,6 +92,7 @@ * **[gcp](code/gcp)** * **[chef](code/chef)** * **[kafka](code/kafka)** +* **[protocol demos](code/protocol_demos/)**
diff --git a/code/protocol_demos/sync-async/async.js b/code/protocol_demos/sync-async/async.js new file mode 100644 index 0000000..6bfea90 --- /dev/null +++ b/code/protocol_demos/sync-async/async.js @@ -0,0 +1,7 @@ +const fs = require("fs"); + +console.log("first"); + +fs.readFile("file.txt", (err,data)=> console.log(data.toString())); + +console.log("second"); diff --git a/code/protocol_demos/sync-async/file.txt b/code/protocol_demos/sync-async/file.txt new file mode 100644 index 0000000..c211a99 --- /dev/null +++ b/code/protocol_demos/sync-async/file.txt @@ -0,0 +1 @@ +gm anon \ No newline at end of file diff --git a/code/protocol_demos/sync-async/package.json b/code/protocol_demos/sync-async/package.json new file mode 100644 index 0000000..b6c1bff --- /dev/null +++ b/code/protocol_demos/sync-async/package.json @@ -0,0 +1,12 @@ +{ + "name": "demo_sync-async", + "version": "1.0.0", + "description": "", + "main": "async.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "" +} diff --git a/code/protocol_demos/sync-async/sync.js b/code/protocol_demos/sync-async/sync.js new file mode 100644 index 0000000..1a3246b --- /dev/null +++ b/code/protocol_demos/sync-async/sync.js @@ -0,0 +1,10 @@ +const fs = require("fs"); + +console.log("first"); + +const res = fs.readFileSync("file.txt"); + +console.log(res); + +console.log("second"); + diff --git a/communication/README.md b/communication/README.md index aa04100..b5c96d2 100644 --- a/communication/README.md +++ b/communication/README.md @@ -119,12 +119,39 @@ curl -v --trace marinasouza.xyz #### Async workload is everywhere - async programming (promises, futures) - async backend processing + - async commits in postgres + - async IO in Linux (epoll, io_uring) + - async replication + - async OS fsync (filesystem cache)
---- -### Push +### Push + +
+ +#### pros and coins + + - real time + - the client must be online (connected to the server) + - the client must be able to handle the load + - polling is preferred for light clients + +
+ +#### basic idea + + 1. client connects to a server + 2. server sends data to the client + 3. client doesn't have to request anything + 4. protocol must be bidirectional + +
+#### used in + + - RabbitMQ (clients consume the queues, and the messages are pushed to the clients)
@@ -133,6 +160,11 @@ curl -v --trace marinasouza.xyz ### Polling +
+ +#### basic idea + - when a request takes long time to process (e.g., upload a video) + - the backend want to sends notification