Mirrord - Overview

When we have a large project with a kubernetes cluster, it’s sometimes difficult to debug and test certain parts of the application. Mirrord allows us to bind a local port to a remote server. flowchart TB request --> mirrord subgraph Pod mirrord -.-x|intercepted| live_server:3000 end mirrord -->|db connection| db[(Database db:5000)] mirrord -->|forwarded| local_machiene(local:3000) local_machiene -.-|connects db:5000 via mirrord| db You can run a local server for example on port 3000 and bind it to a remote server. And any request coming to live_server:3000 will be intercepted by mirrord and forwarded to your local machine. We can debug the incoming request, connect to other services etc… Like our local machiene is a part of the kubernetes cluster. ...

Client - Server Patterns

Client-Server is a common architecture pattern in software systems. It is a distributed system architecture that partitions tasks or workloads between the providers of a resource or service, called servers, and service requesters, called clients. There are different patterns in which client and server can communicate with each other. Request-Response The client sends a request to the server and waits for a response. The server processes the request and sends a response back to the client. It is a synchronous communication pattern. It is used in HTTP, RPC, and other synchronous communication protocols. sequenceDiagram participant Client participant Server Client->>Server: Request Server->>Client: Response Short Polling The client sends a request to the server at regular intervals. The server responds with new data if available. It is a synchronous communication pattern with a short interval. sequenceDiagram participant Client participant Server Client->>Server: Request Server->>Client: Response ( no data ) Note left of Client: Wait for some time Client->>Server: Request Server->>Client: Response ( data ready ) Long Polling The client sends a request to the server and waits for a response. The server holds the request until new data is available or a timeout occurs. It is a synchronous communication pattern with a long timeout. sequenceDiagram participant Client participant Server Client->>+Server: Request Note right of Server: Wait Until data is ready Server->>-Client: Response ( delayed ) WebSockets The client and server establish a persistent, two way communication channel. It is used for real-time communication and updates. It is particularly useful for chat applications, online gaming, and financial trading platforms. sequenceDiagram participant Client participant Server Client->>Server: Establish Connection Server->>Client: Establish Connection Client->>Server: Send Message Server->>Client: Send Message Server-Sent Events The server sends updates to the client over a single HTTP connection. Client sends a request and the server uses the response to send updates. Server will not end the response, and will keep sending updates over the established connection. sequenceDiagram participant Client participant Server Client->>Server: Establish Connection Server->>Client: Send Update Server->>Client: Send Update Server->>Client: Send Update Publish-Subscribe The client subscribes to a topic or event on the server. The server publishes messages to the subscribed clients when an event occurs. It’s similar to WebSockets, but the server can send messages to multiple clients and the messages are partitioned by topics. It is an asynchronous communication pattern. sequenceDiagram participant Client participant Server Client->>Server: Subscribe ( establish a connection ) Server->>Client: Publish ( through the connection ) Request-Callback The client sends a request to the server and provides a callback function or URL. The server processes the request and calls the callback function or URL on the client. It is an asynchronous communication pattern. sequenceDiagram participant Client participant Server Client->>Server: Request ( with callback info ) Server->>Client: Invoke the Callback

Testing - Finding Errors Early

Errors in software systems are inevitable. They can be caused by a variety of factors, including human error, hardware failure, or software bugs. Testing a software helps in finding errors early, It is important to find errors as early as possible to avoid any sort of issues in production. Let’s explore some checkpoints in which errors can be found early. Build Time Compiler performs a syntax check on the code and reports any errors. It includes type checking to ensure that the types of variables are used correctly. The limitations depends on the language and compiler, on how much it can check. Unit Testing Unit tests are written to test individual units of code. It helps in finding errors in the code logic. Unit tests works like a double entry book keeping system. Integration Testing Integration tests helps to check if different systems are interacting correctly, and if the data is being passed correctly. It is very helpful to find errors in systems which are dynamically typed and the cases of interactions needs to be valid. Load Testing Load tests help us to find errors in the system when it is under heavy load. We verify if the system is able to handle the incoming requests and if it is able to respond within the expected time. It also helps identify the limits of the system. End-to-End Testing End-to-End tests are mostly used to test the entire system from start to finish in a user-like environment. It helps find errors in a user point of view, while using the system. typically for e2e systems, we deploy the whole system and have another software interact with it like a user. It’s a good practice to have a combination of these tests to find errors early in the development process. It becomes crucial to run more tests as the system grows and becomes more complex. ...

Bash - Overview

Bash Scripting is a handy and powerful tool for automating tasks on a Unix-like operating system. It is a command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh). Variables Variables in Bash are used to store data. They can be used to store strings, numbers, and other types of data. Variables are defined using the = operator. ...

API Patterns

API is a common concept among software systems. Different software systems require to communicate with eachother to invoke some functionality or to exchange data. Since it’s a frequent requirement, it’s important to have a set of standards. There are different patterns and best practices that can be used to design and implement APIs. RESTful API REST APIs are designed around resources, which are any kind of object, data, or service that can be accessed by the client. They are mainly used for CRUD operations (Create, Read, Update, Delete) on resources. They use standard HTTP methods (GET: Read, POST: Create, PUT: Update, DELETE: Delete) and status codes to perform these operations on the resources. REST APIs are stateless, meaning that calls can be made independently of one another, and each call contains all of the data necessary to complete itself successfully. GraphQL GQL is a query language for APIs and a runtime for executing those queries by using a type system you define for your data. Graphql APIs are designed with a schema that defines the types and fields that can be queried. The Client can request only the data it needs, and the server will return only the requested data. The shape of response follows the shape of the request. gRPC It is designed for low latency and high throughput communication between microservices. gRPC is particularly suitable for microservices and between systems written in multiple programming languages due to its support for multiple programming languages. It based on HTTP/2, which is a binary protocol that is more efficient than HTTP/1.1. It uses Protocol Buffers as the Interface Definition Language (IDL) for describing both the service interface and the structure of the payload messages. Webhooks Webhooks are user-defined HTTP callbacks, which are triggered by specific events. When an event occurs, the source site makes an HTTP request to the URL configured for the webhook. They are useful for integrating different systems or for events in asynchronous communication. WebSocket WebSocket provides two-way (full duplex) communication channels over a single TCP connection. It enables interaction between a client and server in a real-time manner. It is particularly useful for applications that require real-time updates, such as chat applications, online gaming, and financial trading platforms. Each of these standards are useful and are best practices for their specific use cases. It’s important to choose the right pattern based on the requirements of the system. ...

Razor Pages - Overview

Razor pages provides a way to build web applications using a page-focused approach. Under the hood, it uses the same routing and middleware as MVC, and it provides directory-based conventions for views. Pages can have a viewmodel where we can define page data and actions. Pages: Pages are the main part of a Razor Pages application. Pages are created in the Pages directory and are named with the .cshtml extension. Each page can have a corresponding .cshtml.cs file which contains the page model. Page Model: The page model is responsible for handling requests and rendering the page. It is a class that contains the data and actions for the page. The page model is defined in a .cshtml.cs file and is associated with a .cshtml file. Getting Started Create a new project using the dotnet command-line interface. ...

Dotnet MVC - Overview

C# asp.net MVC is a web application framework that provides a model-view-controller architecture. The MVC pattern separates the application into three main components: the model, the view, and the controller. This separation of concerns makes it easier to manage and maintain the application. This structure also makes it easier to test and debug the application. Model: The model represents the data and core business logic related to data of the application. It is responsible for managing the data and the rules for accessing and updating the data. The model is independent of the user interface and can be reused across different views. View: The view is responsible for presenting the data to the user, think of HTML Templates. It is the UI of the application and is responsible for rendering the data to the user. The view is independent of the model and the controller and can be reused across different models and controllers. Controller: The controller is primarily responsible for handling user input and requests. It processes the input, interacts with the model, and selects the view to be rendered. The controller is responsible for the flow of the application and is the glue between the model and the view. Underneath, it uses kestrel server to host the application and uses asp.net core for web development. ...

Scala - Testing

Scala supports testing using the JUnit and ScalaTest frameworks. These frameworks provide a way to write and run tests for your Scala code. JUnit is a popular choice for unit testing in Scala due to its simplicity and extensibility. Writing Tests JUnit provides a set of annotations that can be used to write tests. The @Test annotation is used to mark a method as a test method. The @Before and @After annotations are used to mark methods that should be run before and after each test method, respectively. ...

Rust - Testing

Rust has built-in support for testing with the cargo and assert. We can write tests in Rust using the #[test] attribute and the assert! macro. The cargo command-line interface can be used to run the tests. The tests can be written in the same file as the code being tested, or in a separate file. Writing Tests Suppose we have a function add in main.rs which adds two numbers. // main.rs pub fn add(a: i32, b: i32) -> i32 { a + b } We can write a test for this function in the same file. ...

Python - Testing

Python unittest library is a built-in library that provides a way to write and run tests for your Python code. It is a part of the Python standard library and is widely used for writing unit tests in Python. pytest is another popular choice for testing in Python due to its simplicity and extensibility. Writing Tests unittest provides a set of classes and methods that can be used to write tests. The unittest.TestCase class is used to define test cases, and the assert methods are used to verify the expected behavior of the code under test. ...