Tuesday, August 19, 2025

Kubernetes pods to run microservices that are launched from user generated blog

 Q: In my blogger.com blog I want users to be able to upload pics and create a collage, but I can't have a hosted server do this.. I want Kubernetes pods to be launched when any service request comes, the collage images are sent to the pods and result can be downloaded by the user. Is this possible?

Yes, it is possible to implement the functionality you described using Kubernetes and serverless principles. Here’s an outline of how you can design such a system:


Architecture Overview

  1. Frontend (Blogger Blog)

    • Your Blogger site acts as the frontend where users upload images and request the collage.

    • JavaScript on the blog can handle image uploads and send them to a backend API.

  2. Backend API Gateway

    • Use a cloud-hosted API gateway (e.g., AWS API Gateway, Google Cloud Endpoints) to accept requests.

    • The API gateway triggers the creation of a Kubernetes pod for processing.

  3. Kubernetes Cluster

    • Kubernetes is configured to launch pods on demand.

    • Each pod contains a containerized application that processes the collage request.

  4. Collage Service (Inside Pods)

    • This service receives uploaded images, processes the collage, and stores the result in cloud storage (e.g., AWS S3, Google Cloud Storage).

    • A signed download URL is sent back to the user for retrieving the collage.

  5. Cloud Storage

    • Temporary storage for user-uploaded images and the final collage.

    • Ensures scalability and reduces dependency on persistent storage within pods.


Steps to Implement

1. Blogger Integration

  • Add a custom HTML/JavaScript form to your Blogger blog.

  • Use JavaScript to handle file uploads and communicate with the API gateway.

  • Example (AJAX):

    const formData = new FormData();
    formData.append("image1", file1);
    formData.append("image2", file2);
    
    fetch('https://your-api-gateway-url/upload', {
        method: 'POST',
        body: formData
    })
    .then(response => response.json())
    .then(data => {
        console.log('Download link:', data.download_url);
        // Show the link to the user
    });
    

2. API Gateway

  • Choose a cloud provider for the API gateway:

    • AWS: API Gateway with AWS Lambda to trigger Kubernetes jobs.

    • Google Cloud: Cloud Endpoints or Cloud Functions.

    • Azure: Azure API Management.


3. Kubernetes Pod Auto-Scaling

  • Set up Kubernetes pods with:

    • A containerized application that processes images (e.g., using Python’s PIL library).

    • Horizontal Pod Autoscaler (HPA) to launch new pods based on demand.

  • Use Kubernetes Jobs to run processing tasks.

Example Deployment (YAML):
apiVersion: batch/v1
kind: Job
metadata:
  name: collage-job
spec:
  template:
    spec:
      containers:
      - name: collage-processor
        image: your-collage-processor-image
        env:
        - name: STORAGE_BUCKET
          value: "your-bucket-name"
      restartPolicy: Never
  backoffLimit: 4

4. Collage Service

  • Use a lightweight library like:

    • Python: PIL (Pillow), OpenCV.

    • Node.js: Sharp, Jimp.

  • The service should:

    • Receive image files.

    • Process the images into a collage.

    • Upload the result to cloud storage.


5. Cloud Storage Integration

  • Store images and the final collage in a cloud bucket.

  • Generate pre-signed URLs for:

    • Uploading images to the pod.

    • Downloading the collage.


Challenges and Solutions

  1. Latency:

    • Cold starts of Kubernetes pods can add latency.

    • Use pre-warmed pods or a managed serverless container service (e.g., AWS Fargate, Google Cloud Run).

  2. Security:

    • Authenticate requests using API keys or OAuth.

    • Validate and sanitize user inputs to prevent abuse.

  3. Cost Management:

    • Set limits on pod resource usage and configure auto-scaling policies.

    • Implement a cleanup process for unused files.


This setup avoids the need for a traditional hosted server while leveraging Kubernetes for scalability and cloud storage for persistence. If you’d like, I can help you with detailed YAML configurations or code for specific parts!


Q: Thanks! considering that my blog hardly gets 100 unique visitors in a day, a couple would be interested in making a collage, how much would making one collage cost?

The cost of processing a single collage depends on several factors, including the cloud provider, the configuration of your Kubernetes cluster, and the resources allocated for each pod. Since your blog has low traffic and only a few users would use the collage feature, the costs can be kept minimal by using a pay-as-you-go model. Here’s a breakdown:


Cost Components

  1. Cloud Provider Costs
    You’ll primarily pay for:

    • Compute (CPU & Memory): For the time your pod is running.

    • Storage: For temporary storage of images and collages.

    • API Gateway: For handling requests.

    • Data Transfer: For uploading and downloading images.

  2. Kubernetes Costs

    • If you’re using a managed Kubernetes service (like GKE, EKS, or AKS), you’ll incur costs for:

      • The control plane (often free for low usage in some tiers).

      • The worker nodes, charged by the resources used.

  3. Processing Requirements
    For a simple collage generator:

    • Assume 0.25 vCPU and 256MB RAM for a single pod.

    • Average processing time: ~10-30 seconds per collage.

  4. Storage Costs

    • Temporary storage of uploaded images: Minimal (~1-10MB per collage).

    • Output storage for collages: ~1-2MB per collage.


Estimated Costs per Collage

Component Details Estimated Cost
Compute 0.25 vCPU, 256MB RAM for 30 seconds (~0.0001 hours). ~$0.0000025 per collage (AWS/GCP).
API Gateway One request to trigger the job. ~$0.0004 per request.
Storage (Temporary) 10MB upload + 2MB result stored for <1 day. ~$0.0002 per collage.
Data Transfer 12MB total transfer (upload/download). ~$0.00012 per collage.

Total Estimated Cost per Collage: $0.00072 ($0.001).


Monthly Cost for Your Traffic

Assume:

  • 5 collages/day (max traffic).

  • 30 days/month.

Monthly Cost:

5×30×0.001=0.15USD/month5 \times 30 \times 0.001 = 0.15 \, \text{USD/month}


Cost Optimization Tips

  1. Use Preemptible/Spot Instances:
    If the pod takes only a few seconds, spot instances can reduce costs significantly.

  2. Free Tiers:
    Many cloud providers offer free-tier usage:

    • Google Cloud: 50GB storage free/month, 1 vCPU/month for GKE.

    • AWS: 1 million API Gateway requests and 750 hours of t2.micro free for 12 months.

  3. Minimize Cold Starts:
    Use small and efficient Docker images to reduce startup times.

  4. Batch Processing:
    Queue requests and process multiple collages together to maximize resource usage.


Given your low traffic and minimal resource requirements, you can likely run this setup for less than $1/month in total. It's an extremely cost-effective solution! If you'd like, I can help analyze costs for a specific cloud provider you're considering.

Q: Is this kind of architecture called microservices?

Yes, the architecture you're considering has characteristics of microservices, but it also aligns closely with serverless and event-driven architecture principles. Let's break it down to clarify:


What is Microservices Architecture?

Microservices architecture involves designing an application as a collection of small, independent, and loosely coupled services. Each service focuses on a specific business capability and communicates with others via well-defined APIs.

Key Features of Microservices:

  1. Small, Single-Purpose Services: Each service handles a distinct functionality (e.g., image processing, user authentication).

  2. Independence: Services can be developed, deployed, and scaled independently.

  3. API Communication: Services communicate over APIs (usually HTTP or message queues).

  4. Containerization: Often deployed using Docker or Kubernetes.

Your architecture includes some of these elements:

  • The collage generation pod could be considered a "microservice" that performs one task (image processing).

  • Kubernetes enables independent scaling and containerization.

  • The system communicates via APIs (e.g., API Gateway).


How It Also Aligns with Serverless Architecture

Your approach more closely resembles serverless principles:

  1. Event-Driven: A Kubernetes pod (or job) is launched only in response to an event (user request).

  2. Ephemeral Services: Pods exist only for the duration of the task, which is a hallmark of serverless computing.

  3. Cost Efficiency: You only pay for the compute resources used during the task, avoiding idle costs.

This serverless-style deployment is supported by Kubernetes when configured with event-driven triggers like Kubernetes Jobs or integrations with cloud event systems (e.g., Cloud Run, AWS Lambda with EKS).


Comparison: Microservices vs. Serverless

Aspect Microservices Serverless (Your Case)
Granularity Many small services, each running continuously. Short-lived tasks triggered by events.
Deployment Runs on Kubernetes, VMs, or similar. Uses serverless compute (e.g., pods/jobs).
Scaling Scaled independently based on load. Automatically scaled, no idle resources.
Resource Usage Resources allocated even during idle times. Pay-per-use, zero cost when idle.
Communication Requires inter-service communication. Minimal; tasks are isolated.

Your Architecture

Your design doesn't fully implement microservices since you aren't creating multiple interacting services. Instead, it leverages serverless principles on Kubernetes, with event-driven pods acting as disposable "workers" for a specific task.

Terminology:

  • It can be described as event-driven microservices or serverless workloads on Kubernetes.


Would Full Microservices Be Better?

For your use case (low traffic, simple processing task), microservices might be overkill. Serverless-style architecture is simpler and more cost-effective. However, if your system evolves to include multiple independent features (e.g., collage generation, video editing, user management), adopting a true microservices approach might make sense.

Would you like guidance on scaling this system or adapting it to include more features?

Can you give examples of computer techies getting confused by the commands what seem to screw their minds as in a "mind fuck"?

 Certainly. In the programming and tech world, some commands or behaviors can be unintuitive, misleading, or just bizarre enough to make even experienced developers pause and wonder if reality is breaking. Here are some classic and modern examples of “mind-fuck” moments—commands or situations that confuse or trip up even seasoned computer techies:


๐Ÿ”ง 1. The rm -rf / command

Context: Unix/Linux
Effect: Deletes everything on the root file system.

sudo rm -rf /

Why it’s confusing/terrifying:
Beginners may not understand the consequence, but seasoned users dread this. It's a complete wipeout of the system without warning if protections are disabled. Once executed, there's often no recovery unless backups exist. The very existence of such a command in the hands of anyone is a recipe for disaster.


๐ŸŒ€ 2. JavaScript’s [] == ![]

Context: JavaScript

[] == ![]
// true

Why it melts minds:
It defies intuitive logic. The left side is an empty array, the right side is the negation of an array (which is false), and somehow, [] == false is true. This stems from JavaScript's loose coercion rules and == vs ===.


๐Ÿง  3. Git Detachment Madness

Context: Git

git checkout <commit-hash>

Why it confuses people:
You land in a "detached HEAD" state with a cryptic message. Beginners often don’t understand why their changes aren’t showing up in any branch or why nothing seems to commit “right.”


๐Ÿงจ 4. Fork Bombs

Context: Unix/Linux

:(){ :|:& };:

Why it’s trippy:
This single-line shell function causes an infinite loop of process spawning—crippling the system. It looks like emoji soup to the untrained eye and behaves like malware in disguise. A real "WTF did I just run?" moment.


๐Ÿง™ 5. Python’s is vs ==

Context: Python

a = 256
b = 256
print(a is b)  # True

a = 257
b = 257
print(a is b)  # False

Why it's confusing:
Python caches small integers (−5 to 256). So a is b is True for 256 but not 257. Beginners think is checks value equality, but it actually checks identity (same memory reference).


๐Ÿ•ณ️ 6. C: Buffer Overflow Mayhem

Context: C programming

char buffer[8];
strcpy(buffer, "AAAAAAAAAAAAAAAA");

Why it's a trap:
Beginners don’t realize this overflows into other memory, potentially corrupting execution flow. It’s subtle, works fine in some compilers, crashes in others, and introduces nondeterminism—a classic source of hair-pulling bugs.


๐Ÿ” 7. Bash Brace Expansion Weirdness

mkdir {a,b,c}

Creates:

a/ b/ c/

But:

echo "I have {no, some} idea"

Outputs:

I have no idea I have some idea

Even weirder:

echo {1..3}
# 1 2 3

Why it trips people up:
It’s powerful but incredibly non-obvious. Works like magic until it doesn’t. And good luck spotting a missing comma or unmatched brace.


๐Ÿ’พ 8. Visual Studio Code: settings.json vs Workspace Settings

Context: VS Code
Why it messes with people:
You change a setting globally (settings.json) and wonder why it’s not reflected. Turns out, the workspace or folder-specific settings override it. It’s especially disorienting for users new to the layered configuration model.


๐Ÿ”„ 9. Docker Volume and Bind Mount Confusion

docker run -v $(pwd):/app myimage

Why it’s confusing:
People expect the image’s /app to have its own files, but they get overwritten by the host’s files because of a bind mount. It leads to the question: “Where did my code go?!”


๐Ÿ’ฅ 10. Makefile Tabs vs Spaces

Context: Makefile

all:
    echo "hello"

Why it's evil:
Those must be tabs, not spaces. Use spaces and you get:
make: *** missing separator. Stop.

Mind-breaking moment: Tabs and spaces look identical in most editors. Debugging this becomes an existential crisis.


๐Ÿ˜ต 11. Python: Mutable Default Arguments

def append_to_list(value, my_list=[]):
    my_list.append(value)
    return my_list
append_to_list(1)  # [1]
append_to_list(2)  # [1, 2] <-- WTF?!

Why:
The default value is evaluated once at function definition, not each time the function is called.


๐Ÿงช Bonus: Quantum C++ Moment

int a = 10;
if (a = 5) {
    std::cout << "Surprise!" << std::endl;
}

Why it’s messed up:
Instead of checking if a is 5, it assigns 5 to a. Then if (5) is true. Looks totally legit to most people, and it's a frequent interview trap.


Want me to turn this into a presentation, comic strip, or programming poster?


Dodd namskara GPT avare... Idu artha agtilla innu hyperbole add maadi comic strip anthe!!!

Thursday, June 26, 2025

Execute https://wa.me/91xxxxxxxxxx URL in an Android App to Chat with non contact numbers

If you link your google chrome profile with your whatsapp account..

then while in chrome open the URL https://wa.me/91xxxxxxxxxx

the xxx being an unknown mobile number.. You can rest assured that 

you can chat with that person in WhatsApp without storing the number.

The URL will be executed in an Android App.


After you launch the app..
you can type the number.. no extra permissions needed.
Just press ENTER and off you go with your chat.

Here is the repo in case you are interested: Link

Its created in Android Studio using kotlin language.

Loom video: https://www.loom.com/share/762d9d55fa6b420eabbc78cec0ad9bda?sid=c3a1571b-c746-4993-a39d-45ab511501d4

Monday, June 2, 2025

Full Stack Development in MERN Stack

 Hello,

Tumultus ride it has been as always. Its June,2nd 2025 and as even semester of Academic year 2024-25 is reaching its end, my college went for peer review by NBA and results are awaited. Suffice to say we have learnt what it entails to make graduates with all attributes that we claim they possess.

I(https://jyothyit.ac.in/faculty/mr-mukesh-kamath-bola/) was called upon to handle the subject FSD with Mern stack. It was very tough esp when I didn't know MongoDB that well, let alone expressjs or webpack and modularization.

Here is the manual of our lab that was the outcome of the course.  

FSD-BIS-601-MANUAL

Here are some projects that I demonstrated: https://github.com/bmkamath2000/React-Projs

Sunday, April 20, 2025

Dunder / Magic Methods in Python like __init__()

 Tech with Tim in his python video on Dunder methods in python speaks about

1) __init__() method is a constructor                                



class Rect():

    def __init__(self,x,y):

        self.x = x

        self.y = y

        print("Called __init__ with param %s, %s" % (x,y))

Rect(2,3) => calls __init__ method.

2)  + method is same as __add__()

str1 = "hello"                          

str2 = "world"

new_str = str1 + str2

same_str = str1.__add__(str2)

print(new_str)

print(same_str)


3) __length__() is invoked when len(object) is called                  


str1 = "hello"

str2 = "world"

str1_length = len(new_str)

str2_length = len(same_str)

print(str1_length, str2_length)


4)  __add__(self, oper): is invoked on + operator

     __str__(self): is invoked when the object is printed

class Counter():

    def __init__(self):

        self.value = 1

    def count_up(self):

        self.value += 1

    def count_down(self):

        self.value -= 1

    def __str__(self):

        return f"Count=%s"% self.value

    def __add__(self, oper):

        return self.value + oper.value

count1 = Counter()

count2 = Counter()

count1.count_up()

count2.count_up()

print(count1, count2)

print(count1 + count2)

5) __repr__()   - representation

6) __sub__(),    --subtraction

   __mul__(),      -- multiply

  __truediv__()    -- division

7)__lt__()      --Lessthan, 

   __gt__()     --GreaterThan, 

   __eq__(),    -- Equalto    

  __gte__()  -- Greater than equal, 

   __lte__()  -- Less than equal,

   __ne__()  - notequal

8) __getitem__() in lists obj[item] useful for indexing,

   __setitem__() in lists obj[index]= value,

   __delitem__()in lists del obj[index],

I intended to try out all the methods but lack of time is making me post faster

Tuesday, February 25, 2025

Python Decorators

These features of python are not in any order of importance as such.

I chanced upon a youtube video where "the python dude" was explaining decorators.

It seems like in python we can pass function names as parameter.

Also the passed function can be called from the called function.

Hence our code becomes more useful and more difficult to understand.

import time

def measure_time(func):
    def wrapper():
        start = time.time()
        func()
        end = time.time()
        print(f'Execution time : {end - start} sec')
    return wrapper

@measure_time
def morning():
    print("Good morning")

morning()

Output:

pythonprgms>python pythonprgm5.py 

Good morning

Execution time 0.000936 sec

A similar program with two decorator per function morning is possible:

#It happens because the decorator runs the function immediately.
# The wrapper prevents that and ensures it only runs when you call it.

import time

def measure_time(func):
    def wrapper():
        start = time.time()
        func()
        end = time.time()
        print(f'Execution time : {end - start} sec')
    return wrapper

def greeting(func):
    def wrapper():
        print(f'Hello,')
        func()      
    return wrapper


@greeting
@measure_time
def morning():
    print("Good morning")

morning()

Output:
pythonprgms>python pythonprgm6.py Hello, Good morning
Execution time 0.000936 sec

Similar changes post we can pass arguments to morning function but decorators too need to 
pass same arguments.

# *args , **kwargs
import time

def measure_time(func1):
    def wrapper(*args , **kwargs):
        start = time.time()
        func1(*args , **kwargs)
        end = time.time()
        print(f'Execution time : {end - start} sec')
    return wrapper

def greeting(func2):
    def wrapper(*args , **kwargs):
        print(f'Hello,')
        func2(*args , **kwargs)      
    return wrapper


@greeting
@measure_time
def morning(name):
    print("Good morning %s" % name)

morning("John P Diaz")

Output:
pythonprgms>python pythonprgm7.py Hello, Good morning John P Diaz Execution time : 0.0 sec

Friday, January 17, 2025

Python Dictionaries

 A dictionary in python can contain name value pairs. Like

thisdict = {
    "name" : "Shiva",
    "gender" : True,
    "age" : 45,
}

where thisdict contains name, gender and age of string, boolean and int data type.

On purpose I have created another dict with a JSON as a value of a name-value pair.

thisdict = {
    "name" : "Shiva",
    "gender" : True,
    "age" : 45,
    "assets-json" : {
        "net-worth": 1000000,
        "house-type": "flat",
        "address": ["J P Nagar 5th Ph",
                    "Bangalore",
                    "560034"]
    }
}

I have made use of this dictionary structure in a program which

a. finds the length of the dictionary

b. prints the name, gender and age

c. prints the net-worth of the individual in the dictionary object.


thisdict = {
    "name" : "Shiva",
    "gender" : True,
    "age" : 45,
    "assets-json" : {
        "net-worth": 1000000,
        "house-type": "flat",
        "address": ["J P Nagar 5th Ph",
                    "Bangalore",
                    "560034"]
    }
}

thatdict = {
    "name" : "Harish",
    "gender" : True,
    "age" : 54,
    "assets-json" : {
        "net-worth": 10000000,
        "house-type": "Individual House",
        "address": ["Jayanagar",
                    "Bangalore",
                    "560045"]
    }
}

def length_of_dict(dict_param):
    return len(dict_param)

def display_dict(dict_param):
    print("this dict is of %s" % dict_param["name"])
    gender = "male" if dict_param["gender"] == True else "female"
    print("Age = %s \nGender= %s" %(dict_param["age"], gender))
    print("Net Worth:%s" % dict_param["assets-json"]["net-worth"])

if __name__=="__main__":
    print("Length of thatdict:",length_of_dict(thatdict))
    print("Length of thisdict:",length_of_dict(thisdict))
    display_dict(thatdict)
    display_dict(thisdict)

Output of the program:

Length of thatdict: 4

Length of thisdict: 4

this dict is of Harish

Age = 54

Gender= male

Net Worth:10000000

this dict is of Shiva

Age = 45

Gender= male

Net Worth:1000000