Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am hariharan-uno on github.
  • I am hariharan_uno (https://keybase.io/hariharan_uno) on keybase.
  • I have a public key ASBHuJkcaA5BOowpEdql7Hls2EYRINCk53pq-ERLP3q9tAo

To claim this, I am signing this object:

Effective Engineer - Notes

What's an Effective Engineer?

  • They are the people who get things done. Effective Engineers produce results.

Adopt the Right Mindsets

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@hariharan-uno
hariharan-uno / main.go
Created August 25, 2016 19:35 — forked from lizrice/main.go
Container from scratch
package main
// @lizrice, mostly copied from @doctor_julz: https://gist.github.com/julz/c0017fa7a40de0543001
import (
"fmt"
"os"
"os/exec"
"syscall"
)
@hariharan-uno
hariharan-uno / main.go
Created August 23, 2016 19:33 — forked from julz/main.go
containersched minicontainer
package main
import (
"fmt"
"os"
"os/exec"
"syscall"
)
func main() {
@hariharan-uno
hariharan-uno / vagrant_marksman.sh
Created October 14, 2015 06:20
Shell script to run marksman with correct ports and nats in vagrant
HOSTIP=`netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10`
/home/vagrant/recond -marksman=http://$HOSTIP:3000 -nats=tcp://$HOSTIP:4222 &
echo "recond started..."
@hariharan-uno
hariharan-uno / incrementingslugs.go
Created June 20, 2014 09:09
Auto incrementing slugs
package main
import (
"fmt"
"strconv"
"github.com/extemporalgenome/slug"
)
type person struct {
package main
import (
"github.com/gorilla/websocket"
"io"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
//Copied from https://groups.google.com/forum/#!msg/golang-nuts/dEfqPOSccIc/hoq8jdPTBIcJ
package main
import(
"crypto/rand"
"crypto/tls"
"io/ioutil"
"log"
"net"
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int
main(int argc, char *argv[])
{
int pipefd[2];
pid_t cpid;