Skip to content

Commit 0f35a9a

Browse files
committed
add data-persistence
1 parent 7d77346 commit 0f35a9a

3 files changed

+41
-0
lines changed

data-persistence.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Data Persistence:
2+
3+
LocalStorage or IndexedDB
4+
1. LocalStorage is great for small amounts of data and is very simple to use. !LocalStorage is synchronous, meaning it can block the main thread, leading to performance issues.
5+
2. IndexedDB is more complex, but it's much more powerful and is the recommended solution for larger or more complex data needs. !IndexedDB is asynchronous and non-blocking.
6+
7+
There are a couple of strategies to keep your local storage in sync with the server data:
8+
1. Polling: Regularly fetch the data from the server and update the local storage. How often you should fetch the data depends on your application and how quickly the data changes. This is a simple but potentially resource-intensive solution, especially if the data doesn't change very often.
9+
1. Once you have fetched the data from the server using polling, you can sync it with local storage. You can do this by storing the data in the local storage after processing it. !You need to consider the case where a user might reload or close the page during the polling interval
10+
11+
2. Websockets / Server-Sent Events: If your server supports it, you can use WebSockets or Server-Sent Events to push updates to the client whenever the data changes. This is a more complex but efficient solution, as it minimizes unnecessary data transfers.
12+
13+
3. Versioning / ETags: If your server supports it, you can include a version number or an ETag with each piece of data. Whenever you fetch the data, you can compare the version number or ETag with the version you have in local storage. If the versions don't match, you can update the local storage.
14+
1. To check if `ETags` are supported: `curl -I http://<your-server.com/some-endpoint>` => `ETag: "some-value"`
15+
2. Versioning `curl -I -H "Accept-Version: v1" http://your-server.com/some-endpoint` => `the response should reflect the version you requested in the headers`
16+
17+
4. Last-Modified Header: If your server supports it, you can use the Last-Modified HTTP header to determine when the data was last changed. Whenever you fetch the data, you can compare the Last-Modified date with the date you have in local storage. If the server's date is more recent, you can update the local storage.
18+
1. The Last-Modified header value can be retrieved from the Response object returned by the fetch API in JavaScript. `response.headers.get('Last-Modified');`. Server responds with a 304 Not Modified status if the resource hasn't changed since the client's last request.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### Layered Architecture:
2+
Implementing a layered architecture makes a project modular and easier to maintain. The basic layers could be:
3+
Presentation layer: This layer is responsible for managing the UI and UI logic.
4+
Business layer: Also known as Service layer, it encapsulates all business logic.
5+
Data access layer: This layer is responsible for interacting with the database or any other data store.
6+
Each layer should only interact with its neighboring layers (e.g., Controllers should not be directly querying databases).
7+
8+
### Model-View-Controller (MVC):
9+
The MVC pattern can be used to separate concerns, where the Model corresponds to the data access layer, the View corresponds to the presentation layer, and the Controller acts as the intermediary handling the data flow between them.
10+
11+
### Route-Controller-Service-Model Pattern:
12+
In this pattern, Routes define URL routes, Controllers handle requests and responses, Services contain business logic, and Models define data structures and handle database interactions.
13+
14+
### Domain-Driven Design (DDD):
15+
This approach focuses on the core business logic and aims to create a model of the problem domain that can then be used to guide the design of the software. This approach can be beneficial for complex systems.
16+
17+
### Microservices Architecture:
18+
This is recommended for larger, complex applications. Each microservice is a small application with its own specific business focus, which can be developed, deployed, and scaled independently.
19+
20+
### Event-Driven Architecture (EDA):
21+
Node.js is inherently event-driven, which makes it a good fit for implementing EDA. This approach can help you design applications that are highly scalable and loosely coupled.
22+

session_and_token_authentication.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
### Session-based and token-based authentication depends on the specific use case and the architecture of the system

0 commit comments

Comments
 (0)