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]

Tips to prepare for TOEFL in two weeks

I wanted to share some tips on quickly preparing for the TOEFL iBT test
I had to take TOEFL on a short notice, I had two weeks to take the exam and had prepared using materials that I will share in this post
It helped me get a decent score (106/120) and I wanted to share those incredible materials that helped me with everyone who are looking to ace the exam in a short span of time.

[Read More]