Backend Flashcards

1
Q

Give examples where the request-response protocol does not work

A
  • Chats
  • Notification services
  • Very Long requests
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Push API?

A
  • Client connect to a server
  • Server can send message to a client
  • CLient doesn’t have to request anything
    The Push API allows the server to send a notification to a client even when your site is not open, because it relies on service workers.

You need to use HTTP 2.0 to use the Push API

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

PROs and CONs of Push protocol

A

PROs:
- Real time communication
CONS
- Clients need to be able to handle all the messages (Polling is better for light clients)
- More difficult to scale (than just “Request Response” protocol)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Short Polling or just Polling pattern?

A

It is a protocol where
- Client send a request
- Server respond with a handle
- Server continues to process the request
- Client uses that handle to check for status
- You end up having multiple short requests response as polls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe Long Polling

A

It is a protocol where
- Client send a request
- Server respond with a handle
- Server continues to process the request
- When client requests again for that process the server doesn’t respond until the process is complete

Kafka use this protocol.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where long polling is better than short polling or request/response?

A
  • A request that takes a lot of time to process
    - upload a Youtube video
  • The BE wants to send notifications
    - A user just login

Short polling (a.k.a. AJAX based timer): PROS: simpler, not server consuming (if the time between requests is long). CONS: bad if you need to be notified WHEN the server event happens with no delay.
Long polling (a.k.a. Comet based on XHR) PROS: You are notified WHEN the server event happens with no delay. CONS: Consume more the server resources (specially if it use a THREAD for every request, different if it use node for example)

https://stackoverflow.com/questions/4642598/short-polling-vs-long-polling-for-real-time-web-applications

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

PROs and CONs of long polling

A

PROs
- It is less chatty. Not so many short request as in short polling
- client can still disconnect
CONs
- it is not real-time. If the client is slow sending the second request, it is not going to have the response in real time
- Consumes more resources (specially for Threads architecture)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Server Sent Event

A

it is a protocol that
- work over HTTP, with the request/response protocol
- The response never ends
- it sends chunks of data with some events. The client is smart enough to understand those events (it parses the stream data)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

PROs and CONs of Server-Sent Event

A

PROs:
- Realtime
CONs
- Client must be online
- Client should be able to handle the response. Lighter clients are better with Polling
- HTTP/1.1 (max allowed connection is 6)
- No binary data (as websocket)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain Publish Subscriber Communication Pattern

A

When you have several services that depend one on the other and you want to decouple all the services, do processes async.

It uses a message queue, where the services publish and other services consume it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

PROs and CONs of Publish Subscriber Communication Pattern

A

PROs
- Decoupling
- Good for microservices
- Scalability

CONs
- Message delivery issue (the publisher can’t know if the subscriber/consumer receives the message) or what if the message gets twice
- Network saturation, if a lot of clients try to poll

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Sidecar Design Pattern?

A

(In a microservice architecture, it’s very common to have multiple services/apps often require common functionalities like logging, configuration, monitoring & networking services. These functionalities can be implemented and run as a separate service within the same container or in a separate container.)
———————————————————————————-
A sidecar pattern is a single-node pattern made up of two containers.

The first is the application container which contains the core logic of the application (primary application). Without this container, the application wouldn’t exist.

In addition, there is a Sidecar container used to extend/enhance the functionalities of the primary application by running another container in parallel on the same container group (Pod).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When Sidecar pattern is useful ?

A
  • When you have different languages in different containers and you have one common functionality (this pattern is POLYGLOT, language agnostic)
  • When you have different teams working in different containers
  • A service/component must be co-located on the same container group (pod) or host where the primary application is running.
  • A service which can be independently updated without the dependency of the primary application but share the same lifecycle as primary application.

Examples:

  1. Adding HTTPS to a Legacy Service
  2. Dynamic Configuration with Sidecars
  3. Log Aggregator with Sidecar

https://medium.com/nerd-for-tech/microservice-design-pattern-sidecar-sidekick-pattern-dbcea9bed783

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Push API vs Server Sent Event

A

The Push API allows the server to send a notification to a client even when your site is not open, because it relies on service workers.

SSE (or WebSockets) work as long as the user is using your site.

There are some examples (with documentation) in the Web Push section of the ServiceWorker Cookbook that can help you understand this better.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the advantage of being able to send binary data (for example comparing webSocket vs ServerSentEvent

A

A binary file is usually very much smaller than a text file that contains an equivalent amount of data. For image, video, and audio data this is important. Small files save storage space, can be transmitted faster, and are processed faster.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

webSocket vs Server Sent Event (advantages, disadvantages, use cases)

A

WEB SOCKET
Advantages
- Send binary data (more performant)
- bi-directional data between client and server (for more complex systems)

Disadvantages
- Just use HTTP for the first request, then just TCP (less secure)
- More complex to configure
- Vulnerable to cross site (webSocket) Hijacking

Use cases
- real time poling, chats, media players, multiplayer games

SSE
Advantages
- Easier to implement
- Run over HTTP

Disadvantages
- Mono directional
- Can’t send binary data
- maximum number of open connections restriction

Use Cases
- push notifications, state update, social media news feed

17
Q
A