HJ
다른 글 보러 가기

Indie Log #2

7/2/2024

It's been a long time since the last log. I've done some work on image optimization and other tasks. Here's what I've done.

Cloudflare Workers

I initially planned to use Cloudflare Workers for all server computing but encountered limitations with image transformation. The primary issue was its reliance on edge computing, which only allows pure JavaScript and WebAssembly code. Using pure JavaScript was too slow, and I lack familiarity with WebAssembly. But I had to find the solution.

During my online search for a solution, I came across a library called JSquash and decided to give it a try. Unfortunately, it wasn't successful. It worked well with small images but ran into memory issues with images larger than 2MB. I couldn't figure out a fix for this problem.

After much time and effort, I decided to use Cloudflare Images to avoid spending more time on this issue.

Cloudflare Images

Cloudflare Images is reasonably priced in my opinion. It charges $5 for 100,000 images stored and $1 for 100,000 images delivered. If used with proper caching, it could be a cost-effective solution.

With the paid plan for Cloudflare Workers and Cloudflare Images, I'm required to pay at least $11 a month. As a student, this amount of money cannot be overlooked. It serves as a motivation for me.

Sync and Webhooks

After the image optimization, I added a webhooks feature. It sends a message to a specific URL to notify about content changes. Integrating this wasn't a challenging task. I simply embedded the fetching code within the completion section of the syncing code.

Simple code
function sync() {
	const events = await syncCollection();
	const webhooks = await findWebhooks(collectionId);
	
	const works = webhooks.map(async (webhook) => {
		await send(webhook.url, events);
	});
	await Promise.allSetteld(works);
	
	await finishSync();
}

Unexpected things

I was satisfied until now. However, I found a problematic issue in the sync process. Some parts of the content sync were crashing, ruining consistency. I had to rewrite most of the code to fix this syncing issue.

I’d like to discuss this in detail, but I’ll explain briefly for now. I separated the content into two parts, left and right nodes, to keep the past version. If the left node is the latest content and a sync occurs, then the new updated content is written in the right node. If the sync succeeds, the latest version will be the right node. If it fails, the left node remains the latest version.

Now, the sync process is like a build process. If one of them fails, all the updates roll back to the previous version, even if most of them succeeded.

This has been challenging for me. I'm still uncertain if this will work well.

A Two-Week Absence

I spent a week traveling by bicycle with my friend, which was incredibly refreshing and adventurous. We explored scenic routes, enjoyed the fresh air, and visited beautiful spots along the way. The journey was both physically challenging and mentally rejuvenating.

The rest of the time, I was focused on solving the technical issues mentioned above. The process was quite demanding, but I learned a lot and made significant progress. It was a mix of frustration and satisfaction, but ultimately, it was rewarding to see things coming together.

다른 글 보러 가기

Powered by Writeflow