Understanding Distributed Systems Flashcards

1
Q

Pros of tests?

A
  • working of current feature
  • checking if current changes break existing features
  • well written tests are great documentation
  • by using TDD you force clean code on codebase
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How TDD helps with writing clean code?

A
  • firstly you focus on writing requirements, so tests are more functional and code has more business methods than code methods.
  • To easily write tests, classes needs to be shor, well divided and often written to interfaces.
  • code coverage 100% facilitates refactor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Parts of TDD?

A

Write failing test -> test passes -> refactor

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

What is SUT?

A

System under tests (scope of the test)

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

Types of tests

A
  • unit
  • integration: top-down, bottom-up, hybrid, contract tests
  • end-to-end: user journey
  • Nonfunctional tests like security tests, load tests, performance tests
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What unit tests should check?

A

Public API and state of SUT, which is a class.

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

What is user-journey test?

A

It tests the whole scenario - like process of selecting an item and buying it. Exactly like user.
Pros:
- better testing most valuable functionality of app
- despite it’s big tests, quicker to write and maintain DJ test instead multiply EE tests for each step.

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

What contract tests check?

A

It defines request and response of the dependency. It is used in integration tests to simulate it AND in the dependency test suite. Thanks to this, we are sure that responses are closest to real one.

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

What is testing double?

A

This is prod code dependency which in tests needs to be somehow simulated.

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

Type of test doubles

A
  • fake
  • stub
  • mock
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is fake in the testing scope?

A

lightweight implementation of a dependency, like in-memory db instead of real db.

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

What is stub in the testing scope?

A

test double which just returns things - no way to check how system interacts with it during test.

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

What is mock in the testing scope?

A

smarter stub - we can check how system interacts with it and still simulate return value.

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

Fake vs stub vs mock?

A

Usually fake > mock > stub (especially when fakes are written by an author of real dependency)

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

What is continuous integration?

A

Process of merging changes in code done by developers to master branch with additional automatic checks like “static analysis”, unit tests run on server

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

What is continuous delivery?

A

If pipeline isn’t fully automated, but automation is done as much as possible in current organization, it’s Continuous delivery. Ideally a system where there is manual check on staging env, and then its approval for prod deployment is reachable for all organizations.

17
Q

What is continuous deployment?

A

Extreme version of “continuous” variations. Once PR is approved, everything is automated - new version hits the prod.
Quite rare

18
Q

What are parts of usual CI/CD?

A
  1. Review
  2. Build
  3. Pre-prod rollout
  4. Prod rollout
19
Q

How to do proper review in CI/CD?

A

Most important part.
to do:
- checking tests
- checking feature
- backward-compatibility
- logs

20
Q

What preprod rollout does?

A
  • check if app correctly startup on cluster (no NullPoitner or config exception)
  • smoke tests
  • the same health check system like on prod
21
Q

What is canary deployment?

A

progressive rollout of deployment to subsets of users. Role of thumb are 3 batches. Next bigger than previous.

After each batch comprehensive checks.

22
Q

When rollback (app and db) are used?

A

After rollout, there should be many checks (not only health check):
- performance of service
- time of response

If something isn’t correct, the engineer should retry deployment, rollback and wait on hotfix.

23
Q

What is rollback?

A

It is bringing back previous version of app. It should be a mindless process, because decisions about rollback usually are made in stress moments on prod.

That’s why backward compatibility is so important.

24
Q

What to do when there is big change which simply cannot be backward compatible?

A
  • Divide big task on smaller tasks - thanks to this, usually will be a couple of backward-compatible tasks and one incompatible.
  • Leave incompatible task as the last one.
  • try to make old mechanism and new mechanism works at the same time.

Example:
task: change of producer-consumer schema:
division:
1. Consumer can handle both schema (Can be rollaback)
2. producer can produce new schema messages (Can rollback)
3. Leaving old schema (Cannot rollback, because of new messages in system)

25
Q

What are types of http caching?

A
  • client side caching
  • reverse-proxy
26
Q

What features are used by client-side http caching?

A
  • cache-control (controlling of resource age)
  • e-tag (version-control)
27
Q

What is cache-control?

A

Is the mechanism used for client-side caching based on resource age.

After first request, response has header Cache-Control. It can have many parameters, but most important are:

  • public
  • max-age - defines time after first request where resource isn’t stale

Before next request for this resource, browser calculates age. If resource is stale, request goes to server.

28
Q

What is e-tag?

A

Name of header, where value is id of resources version. Next requests (if they are sent to server) contains If-None-Match header with mentions verision-id. If id didn’t change server responses with code 304 “Not modified” (no resoruce returned), and browser resets age count of this resource

29
Q

Timeline of client-side cache-control with etag

A
  1. First request for resource
  2. Second request:if (max-age is achived) {sending actual request for resourceelse {using cached resource}sending request uses etag and based od versioning results response contains 304 code or new resource.
30
Q

What are good practices in client-side caching?

A

Keeping resources immutable. Each change means new url, so whole etag mechanism isn’t needed. Better performance, because resources is cached forever (until new url will appear). It has some drawback because each new url needs to be stored. (while in etag, there is no need for keeping old version of resources.

31
Q

What is reverse-proxy?

A

It’s a server which sits between the internet and web servers. It hides the web server and mainly servers as protector of web server (load balancing).

32
Q

What are uses of reverse-proxy?

A
  • authentication
  • rate-limiting
  • load balancing
  • caching static content
  • SSL termination
33
Q

What difference between forward proxy and reversed proxy?

A

A forward proxy sits between a group of client machines and the internet, hiding the clients. A reverse proxy sits between the internet and web servers, hiding the web servers.

34
Q

When use forward-proxy?

A

used for client

  • privacy
  • bypassing firewalls
  • content filtering.