christova  

Tech Articles


Collated from various sources. Full copyright remains with original authors.

#datastructures #algorithms

Data Structures and Algorithms

Primitive Data Structures

Integers Floating-point numbers Characters Boolean values

Non-Primitive Data Structures

Arrays: Fixed-size sequence of elements, efficient for random access but inefficient for insertions/deletions. Linked Lists: Dynamic structure of nodes linked by pointers, efficient for insertions/deletions at any position but slower random access. • Stacks: LIFO (Last-In-First-Out) order, used for function calls and expression evaluation. Queues: FIFO (First-In-First-Out) order, used for scheduling and task management. • Trees: Hierarchical structures with a root node, used for representing hierarchical relationships (e.g., binary trees, n-ary trees). • Graphs: Collections of nodes (vertices) connected by edges, used for representing networks and relationships. Hash Tables: Data structures that use hashing to store and retrieve data efficiently, often used for implementing dictionaries and databases.

Choosing the right data structure depends on factors such as:

Data type and volume Required operations (insertion, deletion, search, etc.) Memory usage Efficiency considerations

#oop #objectorientedprinciples

Basic OOP Concepts Explained with Clear Examples:

1. 𝐄𝐧𝐜𝐚𝐩𝐬𝐮𝐥𝐚𝐭𝐢𝐨𝐧 Hide internal data behind public methods. - Example: A BankAccount class keeps balance and pin private. The only way to interact with it is through deposit() and getBalance().

2. 𝐀𝐛𝐬𝐭𝐫𝐚𝐜𝐭𝐢𝐨𝐧 Expose a simple interface, hide the complexity behind it. - Example: An EmailService class gives you sendEmail(to, body). Internally, it handles SMTP connections, authentication, and retry logic. The caller doesn't need to know any of that. They just call one method and it works.

3. 𝐈𝐧𝐡𝐞𝐫𝐢𝐭𝐚𝐧𝐜𝐞 Let child classes reuse and override behavior from a parent class. - Example: An Animal class defines speak(). Dog extends it and returns “Woof!”, Cat extends it and returns “Meow!”. Shared logic lives in one place, and each subclass customizes what it needs.

4. 𝐏𝐨𝐥𝐲𝐦𝐨𝐫𝐩𝐡𝐢𝐬𝐦 Write code that works with multiple types through a common interface. - Example: Define a Shape interface with a draw() method. Now Circle, Rectangle, and Triangle each implement draw() their own way. A single drawShape(Shape s) method works with all of them.

#postgresql #databases #sql

1. 𝐑𝐞𝐥𝐚𝐭𝐢𝐨𝐧𝐚𝐥 𝐃𝐚𝐭𝐚𝐛𝐚𝐬𝐞 The classic use case. PostgreSQL excels at managing structured data with tables, relationships, joins, constraints, and fully ACID-compliant transactions.

2. 𝐃𝐨𝐜𝐮𝐦𝐞𝐧𝐭 𝐒𝐭𝐨𝐫𝐞 PostgreSQL supports JSON and JSONB natively, so you can store and query semi-structured data with ease.

3. 𝐓𝐢𝐦𝐞-𝐒𝐞𝐫𝐢𝐞𝐬 𝐃𝐚𝐭𝐚𝐛𝐚𝐬𝐞 You can use native table partitioning for time-based data, or add TimescaleDB for features like automatic chunking, compression, and continuous aggregates.

4. 𝐆𝐫𝐚𝐩𝐡 𝐃𝐚𝐭𝐚𝐛𝐚𝐬𝐞 Recursive CTEs allow you to model and traverse hierarchies and graph-like relationships directly in SQL. For more advanced graph workloads, the Apache AGE extension brings Cypher query support to PostgreSQL.

5. 𝐆𝐞𝐨𝐬𝐩𝐚𝐭𝐢𝐚𝐥 𝐃𝐚𝐭𝐚𝐛𝐚𝐬𝐞 With PostGIS, PostgreSQL becomes a powerful geospatial database. You can store points, polygons, and other geometries, then run spatial queries like “find all restaurants within 5 km” with excellent performance.

6. 𝐅𝐮𝐥𝐥-𝐓𝐞𝐱𝐭 𝐒𝐞𝐚𝐫𝐜𝐡 𝐄𝐧𝐠𝐢𝐧𝐞 PostgreSQL includes built-in full-text search capabilities through tsvector and tsquery. You get indexing, ranking, stemming, and relevance-based search without needing a separate search engine for many use cases.

7. 𝐌𝐞𝐬𝐬𝐚𝐠𝐞 𝐐𝐮𝐞𝐮𝐞 PostgreSQL can also power lightweight messaging systems. LISTEN/NOTIFY enables pub/sub communication between connections, and SELECT ... FOR UPDATE SKIP LOCKED helps you build reliable job queues directly inside the database.

8. 𝐊𝐞𝐲-𝐕𝐚𝐥𝐮𝐞 𝐒𝐭𝐨𝐫𝐞 Using hstore or JSONB, PostgreSQL can serve as a key-value store as well. Both support indexing, which makes lookups fast. It can be a practical lightweight alternative to Redis for some workloads.

9. 𝐕𝐞𝐜𝐭𝐨𝐫 𝐃𝐚𝐭𝐚𝐛𝐚𝐬𝐞 With the pgvector extension, PostgreSQL can store embeddings and perform vector similarity search. You can create HNSW or IVFFlat indexes and run nearest-neighbor queries, making it a solid option for AI/ML applications.

10. 𝐂𝐫𝐨𝐧 𝐉𝐨𝐛 𝐒𝐜𝐡𝐞𝐝𝐮𝐥𝐞𝐫 With pg_cron, PostgreSQL can schedule recurring jobs directly from the database. This is useful for tasks like cleanup jobs, rollups, reporting, and maintenance workflows.

#JWT #jsonwebtokens #authentication

What is JWT and how it works?

JWT (JSON Web Token) is a compact, URL-safe token used to securely transmit information between a client and a server.

It is most commonly for authentication in modern web apps.

A JWT has three parts separated by dots: xxxxx[dot]yyyyy[dot]zzzzz

1. 𝐇𝐞𝐚𝐝𝐞𝐫: Contains the algorithm used for signing the JWT (e.g., HMAC SHA256 or RSA) and the token type (JWT). 2. 𝐏𝐚𝐲𝐥𝐨𝐚𝐝: Contains the “claims”, statements about an entity (typically, the user) and additional data. 3. 𝐒𝐢𝐠𝐧𝐚𝐭𝐮𝐫𝐞: Used to verify that the sender and ensure the token hasn’t been tampered with. Generated by taking the encoded header, the encoded payload, a secret, and the algorithm specified in the header, and signing it.

How does it work? 1. The user logs in with credentials. 2. The server validates credentials and generates a signed JWT. 3. The server sends the JWT back to the client. 4. The client stores the JWT token (typically in localStorage or cookies). 5. For future requests, the client includes the JWT in the Authorization header.

Key Benefits: - Statelessness: No need to store session information on the server, making APIs more scalable. - Security: Digitally signed to prevent tampering. - Compact: Small size allows for efficient transmission.

#instagram #systemdesign

Designing a system like Instagram involves a complex network of components and services.

Below is the overview of the system of Instagram:

Client Interaction: Users interact through mobile or web apps.

Load Balancer: Helps in providing a balance of requests for API gateways.

API Gateways: Gateway to the micro services.

Write Operations: Uploading comments and uploads sent to the App Server, which further validates the request and writes data along with video processing.

Feed Generation Service: Feeds generation and update service for users.

Read Operations: Routes read operations (e.g., view feed) to appropriate service(s).

Metadata Database: Stores user profiles and post metadata.

Caching: Utilises Redis or Memcached for caching, thereby reducing response times and database load.

Search Service (Elastic search): Indexes users and content for quickly returning relevant results.

Blob Storage: Stores user-uploaded media files (e.g., images, videos).

CDN: Caches and serves static content with low latency.

Video Processing: Responsible for transcoding, resizing, and creating thumbnails for all user-uploaded videos.

Activity Feeds: It lets users know about the likes, comments, and interactions.

Categories of Design Patterns:

1. Creational: Focuses on flexible object creation, making the system independent of specific instantiation methods.

2. Behavioral: Defines interaction and communication patterns between objects.

3. Structural: Manages class and object composition, allowing for efficient and flexible system structures.

Top 10 Design Patterns with Real-Life Examples:

1. Singleton: Ensures a single instance (e.g., printer spooler).

2. Factory: Creates objects without specifying exact classes (e.g., car factory).

3. Adapter: Adapts interfaces for compatibility (e.g., universal power adapter).

4. Facade: Simplifies complex systems (e.g., remote control for home entertainment).

5. Decorator: Adds behavior dynamically (e.g., pizza toppings).

6. Proxy: Controls access as an intermediary (e.g., proxy server).

7. Command: Queues requests as objects (e.g., remote control with device buttons).

8. Template Method: Defines algorithm skeletons for customization (e.g., baking recipes).

9. Strategy: Provides interchangeable algorithms (e.g., online payment methods).

10. Observer: Updates dependencies automatically (e.g., weather app subscriptions).

#designpatterns

#linux #filesystem

How Linux Works

Embark on a journey through the intricate workings of a Linux system, from the moment you hit the power button to the seamless execution of your commands and programs. Dive into the orchestration between user interaction and kernel management that powers every aspect of your computing experience.

Power On: Your journey starts with the push of that power button. The system comes to life, and the BIOS (Basic Input/Output System) kicks in, ensuring your hardware is in top shape.

Master Boot Record: BIOS hands over control to the MBR on your hard disk, which then directs the boot loader to its designated spot.

Boot loader: Picture the boot loader as the conductor, signaling for the kernel to take the stage.

4️⃣ Kernel: Ah, the kernel – Linux's heart and soul. It acts as the liaison between your hardware and the tasks you want to perform.

5️⃣ Initial RAM: The kernel settles into memory, and the system initializes with '/sbin/init' at the helm.

6️⃣ User Space: Now you're in control, with the shell and GUI ready to take your commands.

🔁 Cycle of Operation: - User Mode: You interact with the system, requesting programs or commands to run. - System Mode: When tasks require more privilege, like hardware access, the kernel intervenes, managing requests securely.

🛠️ Kernel's Toolbox: - Process Management: Handling the multitude of tasks you've got going. - Memory Management: Allocating space for your applications and data. - Device Drivers: Communicating with your hardware, from mouse to USB drive. - System Calls: Special requests made by programs. - File System Management: Organizing and storing your files securely.

🧠 Brain of the Operation: The kernel communicates with CPU, memory, disk, and network to ensure smooth execution of your commands and programs.

#database #sql #nosql #acid #aws #azure #gcp

Here are steps to help you choose the appropriate database:

𝗨𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱 𝗬𝗼𝘂𝗿 𝗗𝗮𝘁𝗮 𝗥𝗲𝗾𝘂𝗶𝗿𝗲𝗺𝗲𝗻𝘁𝘀

Analyze the nature of your data, including its structure, volume, and complexity. Determine if your data is structured (relational), semistructured (like JSON or XML), or unstructured (e.g., text, images). Consider the growth rate of your data and whether it's transactional or analytical.

𝗜𝗱𝗲𝗻𝘁𝗶𝗳𝘆 𝗬𝗼𝘂𝗿 𝗨𝘀𝗲 𝗖𝗮𝘀𝗲𝘀:

Define the specific use cases your application will have, such as read heavy, write heavy, complex queries, realtime analytics, or simple CRUD operations.

𝗦𝗰𝗮𝗹𝗮𝗯𝗶𝗹𝗶𝘁𝘆 𝗥𝗲𝗾𝘂𝗶𝗿𝗲𝗺𝗲𝗻𝘁𝘀:

Determine if your application needs to scale horizontally (adding more servers) or vertically (upgrading server resources). Look at the database's ability to handle increased loads and traffic.

𝗗𝗮𝘁𝗮 𝗖𝗼𝗻𝘀𝗶𝘀𝘁𝗲𝗻𝗰𝘆:

Decide whether your application requires strict ACID (Atomicity, Consistency, Isolation, Durability) compliance or if eventual consistency is acceptable.

𝗤𝘂𝗲𝗿𝘆 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆:

Consider the types of queries your application will run and whether the database can efficiently handle them. Evaluate the indexing and querying capabilities.

𝐃𝐚𝐭𝐚 𝐌𝐨𝐝𝐞𝐥:

Choose between relational databases (SQL) and NoSQL databases based on your data structure and query requirements.

𝗖𝗼𝗺𝗽𝗮𝘁𝗶𝗯𝗶𝗹𝗶𝘁𝘆 𝘄𝗶𝘁𝗵 𝗧𝗲𝗰𝗵𝗻𝗼𝗹𝗼𝗴𝘆 𝗦𝘁𝗮𝗰𝗸:

Ensure that the selected database integrates well with your existing technology stack and frameworks.

𝗙𝘂𝘁𝘂𝗿𝗲 𝗚𝗿𝗼𝘄𝘁𝗵:

Think about the longterm scalability and growth of your application and whether the chosen database can accommodate future needs.

Based on my understanding, I've compiled a list of databases, which I've updated from the diagram initially provided by Satish Gupta. Please note that this list may not cover all databases, and I might have overlooked some. Additionally, there may be databases that can serve multiple use cases. The intention here is to categorise databases based on use cases or sql/nosql/newsql databases

#authentication #credentials #ssh #oauth #ssl

In today's tech landscape, authentication stands as the sentinel guarding our digital interactions. It's the shield against unauthorised access and data breaches, ensuring the sanctity of sensitive information and user trust.

🔐 Let's break down the top four authentication mechanisms:

1️⃣ Credentials: The classic username-password combo. Simple yet susceptible to attacks like brute force and phishing if not fortified properly.

2️⃣ SSH Keys: A robust method for remote access, leveraging cryptographic keys to grant entry securely.

3️⃣ OAuth 2.0: The backbone of secure web and mobile app interactions, allowing limited access without compromising login credentials.

4️⃣ SSL Certificates: Safeguarding data transmission through encryption, ensuring secure online transactions and communications.

Top 5 Kafka Use Cases Transforming Industries:

Data Streaming 🌊: Monitor and act on real-time data across your organization.

Log Aggregation 📚: Manage large volumes of log data efficiently.

Message Queue 📨: Scale microservices communications with fault tolerance.

Web Activity Tracker 🕵️‍♂️: Customize user experiences with real-time insights.

Data Replication 🔁: Sync data seamlessly across systems.

Kafka simplifies real-time data processing and ensures high availability with its robust architecture. Here’s a breakdown of its key components:

🔹 Producer: Initiates data streams, pushing records into Kafka topics for processing. 🔹 Consumer: Receives and processes data from Kafka topics, driving real-time analytics and applications. 🔹 Broker: The core unit of Kafka infrastructure, managing data storage, distribution, and replication. 🔹 Replica: Ensures fault tolerance and data durability by replicating partitions across multiple brokers. 🔹 Cluster: A collection of Kafka brokers working together to handle data streams and ensure high availability. 🔹 Topic: Logical channels for organizing and categorizing data streams in Kafka. 🔹 Partitions: Divides topics into smaller, scalable units, enabling parallel processing and load balancing. 🔹 Leader Replica: Handles read and write operations for a partition, ensuring consistency and reliability. 🔹 Follower Replica: Replicates data from leader replicas, providing redundancy and fault tolerance.

Kafka is designed to make data streaming seamless and efficient, empowering your real-time data analytics and applications.

#kafka #messagequeues

Enter your email to subscribe to updates.