Why my website looks like "shit" and a bit more about TCP

So the current total size of my website is 7.46 KB, to be exact

Its served on github pages and it uses content-encoding zstd by default, transferring only 4.17KB with compression.

When you open up can.kurttekin.com from your browser the server has no idea about the amount of data can be transmitted per second (bandwith). 
Sending huge amount of data right off can cause packet loss, router owerwhelming etc.

So there is a method 
TCP Congestion Control is a set of strategies that TCP uses to prevent overloading the network.
In Slow Start Phase the server begins with a small congestion window, its measured in segments(MSS 1460 bytes for ethernet)
After every RTT(Round Trip Time) which sending a packet until ACK comes back, congestion window grows exponentially.
The amount of data doubles every RTT, as long as all segments ack'ed.

initial congestion window = 2^0 = 1 segment (~1460bytes)
After 1 RTT / ACK cwnd = 2^1 segments (~2929 bytes)
2 RTT / Next ACK cwnd = 2^2 segments (~5840 bytes)
...
until a packet loss/no ACK received.

https://filipv.net/effects-of-latency-and-packet-loss-on-tcp-throughput/
It is called slow start because it doesnt instantly blast full bandwith, its more cautious. Once a packet lost
TCP enters Congestion Avoidance, where growth slows to linear.

Modern TCP (RFC 6928) start with 10 segments. 
With 1460 bytes per segment, that is ~14.6 KB of data in the very first RTT.
40 bytes for header, 16 bytes for IP and 24 bytes for TCP.

https://www.embedic.com/technology/details/introduction-to-ethernet-ip-tcp-http


With some basic HTML tricks like coding whole page in single line to avoid space and lines, minimal style and removing some bytes from self closing tags
i managed to keep the info i want to give about me under 10kb which made my website widely accessible(even with 40kbps GPRS connection). Because the amount of data stored in data center and transferred is so small it significantly lowered the CO2 emission compared to "good looking" 500mb+ javascript bloated personal websites.

Sockets explained

They act as endpoints in a two-way communication channel.
For communication of two machines or applications each app/machine creates a socket.
Each socket is associated with IP and port. 

OSI
Sockets operate at layer 4 - transport layer.
Application layer calls down the socket api, for example browser, backend server etc

Types of Sockets:
- TCP(Transmission Control Protocol)
Connection oriented and responsible for ensuring reliable, ordered, error checked, non duplicate data transmission.
Before data is sent a three way handshake is performed to establish the connection.(exchange of SYN and ACK packets)
        - Client sends a SYN(synchronize) packet to initiate a connection.
        - SYN-ACK server responds with a SYN-ACK packet, acknowledging the receipt of SYN and sending its own SYN request.

USB C Modding Old Tech

 I will be adding the things i usb c-fied in my life to this post, i am too lazy to write tutorial but one day i might edit this.
Starting with my Natural Ergonomic Keyboard 4000.

 


Domain Models

In this blog post, we’ll dive into the concept of domain models, explore the differences and discuss how these choices impact your software design.

WTH is a Domain Model?
Instead of saying something like "the term domain model refers to an abstraction that represents the real-world concepts and behaviors of a system" i find that stackoverflow reply more helpful:

If you were to take your program and strip away the gui and the DBMS, and replace it with a command line interface, and a MySQL server instance, then port the whole thing to a different platform with different system calls and file system access api calls, the part that you didn't change in that process is the domain model.


Types of Domain Models

Repurposing Android Phone as UMPC

 

I will be sharing  details and files in my GitHub repo so you can build yourself.
https://github.com/cankurttekin/umpc-phone
 

Lenovo Erratic Touchpad Fix

My touchpad felt laggy and jumpy on my Lenovo Yoga 7 after a week i bought it. It starts with finger rubbing and it is not OS related doesnt go away if i dont press to hard on it to make it contact with something on the body and release the static energy. I opened up the laptop and observed the issue and its grounding problem. 

On the left side there is squishy conductor, its almost went deep inside and doesnt make contact with touchpad. I tried poking it with screwdriver to reform to its original shape. This fixed problem but after couple days it looses that squishy form again and problem starts again.  I added aluminium foil to right one, i made a bit thicker where it contacts squishy thing so when touchpad screwed in to place it should contact.

Dependency Injection

When you have different objects and services that does different things and developed by different teams how do you connect them becomes an issue.

DI is a design pattern that aims to decouple object from their dependencies. Instead of creating their own dependencies internally, object receive them from an external source. By using DI we can configure as needed at runtime; with DI dependencies injected at runtime rather than at compiling.

Dependency injection works together perfectly with SOLID principles.
Single Responsibility Principle - DI can help you isolate responsibility of class.
Open-Closed Principle - With new functionalities we can inject new dependencies instead of changing code base.
Dependency Inversion Principle - Dependencies depend on interfaces instead of concrete classes.

There are three types of DI: Constructor Injection, Setter Injection and Interface Injection.

I will give examples as POJO classes, this pattern can be applied to any language and there are solutions in Spring and .NET.

I will build an awesome(?) music lister that lists your musics from particular artist.

How To Secure Your Spring Application

When developing an API for a business, one of the key requirements often revolves around managing different user types and their respective permissions. In this scenario, we'll focus on three user types: admin, individual user, and corporate user.

User Roles Overview:

  • Admin: Has all the privileges of the individual and corporate users, plus additional administrative capabilities.
  • Individual User: Accesses standard user features.
  • Corporate User: Similar to the individual user but may have access to additional resources or features tailored for corporate use.

In this post, we’ll focus on implementing the authentication and authorization mechanisms necessary to enforce these roles, ensuring the system adheres to the statelessness principle of REST.

Understanding Authentication and Authorization

Authentication vs Authorization: What's the Difference? - javatpoint
Authentication vs Authorization image from javatpoint.com 
 

Event Sourcing Pattern

An architectural pattern that models the state changes made by applications as an immutable sequence or “log” of events. Instead of modifying the state of the application in-place.



Generally with crud applications we hold only current state not how we got there. That might be issue for some applications. For example lets think an online banking application. If only thing they can see is current balance not how they got to that balance, no withdrawal, deposit or fee history.

Immutability

Immutability refers to the property of an object or data structure that is can not be modified or changed after it is initialized. Once an object created, its state can not be altered, if there is a need for a change than new object created with those changes and first one will be stay unchanged. This is valuable design choise for data integrity concurreny in multi threaded applications. Immutable objects are useful in scenarios where consistency and predictability are crucial. In some applications you wouldnt want your same data be changed simultaneously by different parts of the application.

Why?
When a data leaves a source, it passes through many different systems, each system uses a point of this data and transfers it to another system. For example, a data coming out of the database gets the first shape on a programming language, then it is kept in the necessary "stacks" and "queues" on various "pipelines", then different "threads" use the data, various "message queues" send the data to "microservices" on servers running in different locations, they use something from the data and the data ends its journey at some point. But during this journey, many different pieces of code compete to process this data, and some access and process this data first, some later.
 
Thats where immutability shines. If this data is not immutable, we will be dealing with possible problems during the entire journey of the data. If the first code runs a few milliseconds late for very different reasons, and the second code handles that data before and deletes the required value, it is possible that we will encounter a problem at that moment.