Clean Code vs A Philosophy of Software Design

Reading through many lines of code in Golang and Java makes for an interesting observation from the codebase which I was taking a look.

There were different styles of coding and it was obvious from reading code that is written by experienced gophers.

People on team who do both Java and Golang use the same Java style in Golang as well.

While most Java programmers come from Clean code school of thought where functions are decomposed into many smaller functions which results in function explosion in the same file.

[Read More]
go  java 

SQS vs SNS vs Kinesis

ServiceThink of it as
SQSA durable queue between producers and consumers
SNSA fan-out notification system
KinesisA high-throughput event stream

SQS:

Is ideal when

  • Producers and consumers run at different speeds
  • You want retry, durability, and backpressure
  • Each message should be processed at least once

SNS

SNS is about fan-out, not durability for processing.

  • Push-based
  • One message → many subscribers

Subscribers can be: SQS queues or HTTP endpoints or Lambda

[Read More]
aws 

Implement mutex using channels

Concurrency primitives can be implemented on top of channel abstraction of CSP style. Here is an example of implementing mutex using channels.

Go code to implement mutex using channels.

package main

import "fmt"

type Lock struct {
	locked chan bool
}

func NewLock() Lock {
	lock := Lock{locked: make(chan bool, 1)}
	lock.locked <- true
	return lock
}

func (l *Lock) Lock() {
	<-l.locked // read from channel and if another read happens it waits
}

func (l *Lock) Unlock() {
	// This is not reentrant

	// calling unlock again on an unlocked channel blocks
	l.locked <- true // write to channel so, that it gets read and channel clears
}

This is not reentrant

[Read More]