<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by George Thomas on Medium]]></title>
        <description><![CDATA[Stories by George Thomas on Medium]]></description>
        <link>https://medium.com/@georgeagain?source=rss-55248a3646fa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*9lJut1mpVozC_RYSH6GA5w.jpeg</url>
            <title>Stories by George Thomas on Medium</title>
            <link>https://medium.com/@georgeagain?source=rss-55248a3646fa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 22:29:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@georgeagain/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What is serverless and why should you use it?]]></title>
            <link>https://medium.com/@georgeagain/what-is-serverless-and-why-should-you-use-it-4fae5fdd0a3d?source=rss-55248a3646fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fae5fdd0a3d</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[George Thomas]]></dc:creator>
            <pubDate>Wed, 22 Apr 2026 20:28:51 GMT</pubDate>
            <atom:updated>2026-04-22T20:28:51.840Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CT8NPYJ7e91Zo3rK6MNBOA.png" /></figure><p>Serverless is a way of running application code only when there is actual work to do. Instead of keeping a service running all the time, a serverless platform starts your code when a request or event arrives and stops when the work is finished. That can reduce idle cost, scale more naturally for bursty traffic, and simplify operations for request-driven applications. It also changes tradeoffs around startup behavior, runtime limits, observability, and application design. To understand those tradeoffs, it helps to compare the older container-based model with the lighter-weight execution models many serverless platforms use today.</p><h3>The dominant model: containers</h3><p>Containers became popular because they made applications easier to package and deploy. Instead of manually configuring machines, developers could package an application with its dependencies and run it in a predictable environment. This made deployments more portable, repeatable, and easier to reason about. A container is usually a process running on a host operating system. It does not normally boot its own full operating system. Instead, it shares the host kernel and uses features like <a href="https://en.wikipedia.org/wiki/Linux_namespaces">namespaces</a> and <a href="https://en.wikipedia.org/wiki/Cgroups">cgroups</a> to isolate the process and control resources. That model works extremely well for many systems. It is one of the reasons modern cloud development looks the way it does. But containers still behave like service-sized units. You start a container, the process begins, the application runtime loads, memory is allocated, and the service waits for traffic. Even when there is no work happening, the service still exists as a running process. That is a natural model for long-running services, but it is not always the most natural model for request-driven applications.</p><h3>The emerging model: isolates</h3><p>Serverless platforms move toward a smaller execution unit. Instead of thinking primarily in terms of long-running services, they think in terms of short-lived pieces of execution. A request arrives, code runs, and when the work is finished, the execution can disappear. One way platforms make this possible is through isolates. An isolate is a lightweight, sandboxed execution environment inside a shared runtime. The term is often associated with V8 isolates, but the broader idea is not limited to Chrome or JavaScript. WebAssembly runtimes can provide similar isolate-like execution through separate Wasm instances and isolated linear memory. Some platforms use microVMs, which are heavier than isolates but still part of the broader movement toward fast, demand-driven execution. The important idea is that isolates move the boundary inward. Containers isolate at the operating system and process level. Isolates isolate inside the runtime itself. That one difference is why they can be much cheaper to create.</p><h3>Where the boundary lives</h3><p>The real difference between containers and isolates is not just that one is “faster” than the other. The deeper difference is where the system draws the isolation boundary. In a container-based model, each unit of execution is a process. The operating system is responsible for enforcing the boundary around that process. In an isolate-based model, many execution units can live inside one already-running runtime process. Each isolate gets its own memory space or heap, but the runtime itself is shared. Here is a simplified view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k_CV1O8U3DFQHhdjVyGOxw.png" /></figure><p>This diagram shows the heart of the difference. With containers, each unit carries its own process, runtime, heap, and application state. With isolates, the runtime is already running, and each new unit mostly needs its own isolated heap and execution context. Containers create another running environment. Isolates create another execution context. That is why the startup behavior is so different.</p><h3>Why startup time matters</h3><p>Startup time matters because it determines how small each request-sized piece of work can be. When a container starts cold, the platform may need to create the container’s isolation layer, start a process, initialize the language runtime, load the application code, allocate memory, and prepare the service to receive traffic. Even when this is optimized heavily, there is still meaningful work involved. An isolate has a smaller startup path. The runtime process is already alive. The engine is already initialized. The platform can create a new isolate, attach code or use cached compiled code, create its own memory space, and begin running it. That does not mean isolates have no startup cost. They do. But the cost is smaller because less has to be created from scratch. The key idea is simple: containers start whole running environments, while isolates start smaller pieces of work inside an already-running runtime. That difference is what makes serverless feel fast.</p><h3>What makes serverless powerful?</h3><p>Serverless becomes powerful when execution units are cheap enough to create on demand. If starting a unit of execution is expensive, you need to keep it running. That is the container model. You keep services alive so they are ready when traffic arrives. If starting a unit of execution is cheap, you can create it when work arrives. That is the serverless model. The platform does not need to keep every possible execution running ahead of time. It can react to demand. This changes how scaling works. In a traditional service model, you scale by adding more running services. In a serverless model, you scale by running more executions. The application does not need to be fully alive all the time. It only needs to run when there is something useful to do. That is why serverless feels like a more natural fit for request-driven applications. Traffic arrives in bursts. User activity changes throughout the day. Background jobs come and go. Most systems do not need every part of the application running at full capacity all the time. Serverless uses computing resources more in line with actual demand.</p><h3>The cost model shift</h3><p>The cost difference comes from the same place. With containers, you often pay for provisioned capacity. Even if your service is idle, the process is still running somewhere. It is still using memory. It may still reserve CPU. It still needs to be deployed, monitored, and scaled. With serverless, the ideal model is closer to paying for execution. Code runs when work exists. When there is no work, there is little or nothing to run. A simple way to say it is: you stop paying for waiting. That is not always perfectly true in every platform or every workload, but it captures the direction of the model. Serverless reduces the amount of infrastructure that exists only to be ready for future traffic. This is especially powerful for applications with uneven demand. A service that receives traffic only occasionally may still require a running container in a traditional model. In a serverless model, that same work can often be handled only when a request arrives. The result is not just lower cost. It is a different relationship between software and infrastructure. The infrastructure becomes more like a runtime.</p><h3>Why has serverless not taken over everything?</h3><p>If serverless is so powerful, it is fair to ask why every application is not already built this way. The answer is that serverless solves one set of problems while exposing another. The first challenge is state. Running a short-lived function is easy. Building a real distributed application usually requires durable state, coordination, ordering, retries, and observability. Those concerns do not disappear just because the compute layer is serverless. The second challenge is portability. Each serverless platform has its own runtime model, APIs, deployment format, and operational assumptions. Code written for one provider is often not easy to move to another. This makes developers cautious, especially when the platform becomes deeply tied to application behavior. The third challenge is tooling. Containers have a mature local development story. Developers understand how to build, run, debug, and deploy them. Serverless development is improving, but it can still feel fragmented across vendors and platforms. There is also a security tradeoff. Containers rely on operating-system and process-level isolation. Isolates rely more heavily on runtime-enforced isolation. That does not make isolates insecure, but it does move the trust boundary. The platform must trust the runtime to enforce memory separation and sandboxing correctly. These challenges are real. But they do not erase the power of the model. They show where the next layer of abstraction needs to emerge.</p><h3>What should we expect to happen?</h3><p>The trend is clear: execution units are getting smaller. We moved from physical machines to virtual machines. We moved from virtual machines to containers. Now serverless platforms are moving us toward isolates, Wasm instances, microVMs, and other lightweight execution models. Each step makes compute more flexible. Each step reduces the cost of starting work. Each step moves developers a little further away from managing infrastructure directly. The next question is not only how we deploy code. The next question is how we express distributed systems when the platform can create execution units on demand. If compute becomes cheap, fast, and portable, then developers should not have to manually wire together every queue, retry, service boundary, deployment target, and runtime behavior. The system should understand more of the application’s intent. That is the direction <a href="https://distlang.com/">DistLang</a> is exploring. Serverless shows that infrastructure can behave more like a runtime. DistLang asks what <a href="https://github.com/distlanglabs/distlang">programming distributed systems</a> could look like once we fully embrace that idea.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fae5fdd0a3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building transient which stores data the way people communicate]]></title>
            <link>https://medium.com/@georgeagain/building-transient-which-stores-data-the-way-people-communicate-e6e4c31e5807?source=rss-55248a3646fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6e4c31e5807</guid>
            <category><![CDATA[distributed-computing]]></category>
            <category><![CDATA[scaling]]></category>
            <category><![CDATA[distributed-ledgers]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[George Thomas]]></dc:creator>
            <pubDate>Fri, 20 Feb 2026 05:44:58 GMT</pubDate>
            <atom:updated>2026-02-20T05:44:58.020Z</atom:updated>
            <content:encoded><![CDATA[<p>People around the world learned to communicate over generations. The way learn about something is through our network or the People around us. Information traditionally transmitted where everyone participated in this process(Now it might be Influencers!). This form of communication works and information still travels quickly if it is important enough. The news may reach a different part of the world if it is pressing enough.</p><p>This method of message passing between people is quick. The same idea can be brought to the world of web applications where data bases could use a similar approach. If there are enough small instances around the world, they can communicate with each other quickly enough to spread the information. If we are to design something like this, the way we can configure this is with a way to specify the world first. The world consists of total number of nodes in the world and the number of nodes one node will communicate to.</p><pre>{<br>  &quot;totalNodes&quot;: 4,<br>  &quot;gossipPeersPerRound&quot;: 2<br>}</pre><p>Every node has a state that is local and also knowledge of the world around it. The data structure could look something like this.</p><pre>{<br>  &quot;local&quot;: { &quot;value&quot;: 5, &quot;ts&quot;: &quot;2026-01-16T12:00:00Z&quot; },<br>  &quot;global&quot;: {<br>    &quot;0&quot;: { &quot;value&quot;: 5, &quot;ts&quot;: &quot;2026-01-16T12:00:00Z&quot; },<br>    &quot;1&quot;: { &quot;value&quot;: 9, &quot;ts&quot;: &quot;2026-01-16T12:00:03Z&quot; },<br>    &quot;2&quot;: { &quot;value&quot;: 10, &quot;ts&quot;: &quot;2026-01-16T12:00:04Z&quot; },<br>    &quot;3&quot;: { &quot;value&quot;: 15, &quot;ts&quot;: &quot;2026-01-16T12:00:05Z&quot; }<br>  }</pre><p>Every node just needs to communicate with a few random peers. The network eventually will have the data everywhere pretty quickly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*euA7XY7V7SvyAoQsIjFl_w.png" /><figcaption>How every node communicates with another node</figcaption></figure><p>The diagram below is how a request can be saved at a location and transmitted around the world. So when a message comes to a Node, it updates the local value and gossips to a set of randomly chosen peers.</p><pre><br>                 +------------------+<br>                 |   Client/Script  |<br>                 | POST /key/save   |<br>                 +---------+--------+<br>                           |<br>                           v<br>                   +-------+--------+<br>                   |   Node N       |<br>                   | local + global |<br>                   +-------+--------+<br>                           |<br>              local update + ts<br>                           |<br>                           v<br>            gossip trigger (if changed)<br>                           |<br>                           v<br>               select random peers<br>                           |<br>        +------------------+------------------+<br>        |                                     |<br>        v                                     v<br>+-------+--------+                    +-------+--------+<br>|   Node A       |                    |   Node B       |<br>| POST /gossip   |                    | POST /gossip   |<br>+-------+--------+                    +-------+--------+<br>        |                                     |<br>   merge global                            merge global<br>   compute gossipDelayMs                   compute gossipDelayMs<br>        |                                     |<br>        +-------------&gt; if changed, gossip ----+</pre><p>In a system like this the number of messages a node talks to is important. It is not an issue when there are a few nodes. If every node is talking to every other node, it becomes a big problem when there are 1000s of nodes. There will be a lot of messages that will be sent between the nodes for synchronization. This project is a way to explore that. Based on how people communicate, Information travels fast even if everyone does not talk to everyone. We might be able to see really low gossipDelay even when the number of random peers a node talks to decreases.</p><p>There is a paper which talks about this in a different context but they explore the same concept of how many messages are required <a href="https://www.cs.cornell.edu/projects/Quicksilver/public_pdfs/SWIM.pdf">https://www.cs.cornell.edu/projects/Quicksilver/public_pdfs/SWIM.pdf</a></p><p>If you want to check out transient and try it out check this repository. <a href="https://github.com/georgethomas111/transient">https://github.com/georgethomas111/transient</a></p><p>Eventually I want to get a graph of number of nodes against the gossipDelay with number of messages between peers as a different dimension to see if the claims in the paper can be validated. If someone else gets to it before me let me know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6e4c31e5807" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streaming messages from a server in GO using GRPC]]></title>
            <link>https://medium.com/@georgeagain/streaming-messages-from-a-server-in-go-using-grpc-5e42b0549301?source=rss-55248a3646fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e42b0549301</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[grpc-client]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[grpc-web]]></category>
            <dc:creator><![CDATA[George Thomas]]></dc:creator>
            <pubDate>Sat, 15 Mar 2025 02:15:25 GMT</pubDate>
            <atom:updated>2025-03-15T02:17:37.200Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why Should I Use Streaming?</h4><p>A typical web application follows a client-server architecture. In this setup, the client typically controls when the interaction happens. This introduces some restrictions on the kinds of applications that can be built. In many cases, the number of messages exchanged between the client and server can be significantly reduced if the server can push information to the client.</p><p><a href="https://grpc.io/">gRPC</a> is an alternative to traditional HTTP-based applications. It provides an abstraction over HTTP protocols, allowing developers to focus on the communication logic rather than the low-level details. gRPC uses Protocol Buffers (<a href="https://protobuf.dev/">protobuf</a>) as the format for transferring data between the client and server. Protobuf is a binary format, which makes it much more efficient than formats like <a href="https://www.json.org/json-en.html">JSON</a> or <a href="https://msgpack.org/index.html">MsgPack</a>, which are not binary.</p><p>However, one limitation with gRPC is that protobuf files must be defined and compiled ahead of time.</p><p>Here is an example of a simple protobuf file:</p><pre>syntax = &quot;proto3&quot;;<br>option go_package = &quot;github.com/georgethomas111/img-proxy/learn&quot;;            <br><br>package learn;<br><br>service Learn {                                                                 <br>  rpc Gossip(GossipRequest) returns (stream Messages);                          <br>};                                                                                                                   <br><br>message GossipRequest {<br>  string id = 1;<br>};      <br>        <br>// The response message containing the greetings                                                                     <br>message Messages {                                                                                                   <br>  string info = 1;                                                                                                   <br>};</pre><p>In this example, we define the format for communication between the client and server. The go_package option specifies where the generated Go package will be located.</p><p>After this, we need to compile the protobuf into a Go package to use it in our code. This is copied from my Makefile but these options helped me generate the go package.</p><pre>.PHONY: generate<br>generate:<br> protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative learn/simple.proto</pre><p>The protobuf compiler is available <a href="https://github.com/protocolbuffers/protobuf">here</a>.</p><h4>Client-Side Code</h4><p>On the client side, we connect to the server and obtain a stream. Go channels are used to handle incoming messages, allowing the application to stay clean and organized. Channels are used for receiving updates from the server and handling errors.</p><pre>package main<br><br>import (<br> &quot;context&quot;<br> &quot;errors&quot;<br> &quot;fmt&quot;<br> &quot;sync&quot;<br> &quot;time&quot;<br><br> &quot;github.com/georgethomas111/img-proxy/learn&quot;<br> &quot;google.golang.org/grpc&quot;<br>)<br><br>type client struct {<br> stream     learn.Learn_GossipClient<br> grpcConn   *grpc.ClientConn<br> grpcAddr   string<br> cliName    string<br> Updates    chan string<br> Errors     chan error<br> KillClient chan int<br>}<br><br>func New(grpcAddr string, cliName string) *client {<br> c := &amp;client{<br>  grpcAddr:   grpcAddr,<br>  cliName:    cliName,<br>  Updates:    make(chan string),<br>  Errors:     make(chan error),<br>  KillClient: make(chan int),<br> }<br><br> ctx, cancel := context.WithCancel(context.Background())<br><br> // This is to ensure that there is a way to<br> // cancel the client without leaks.<br> go func() {<br>  for {<br>   &lt;-c.KillClient<br>   cancel()<br>   c.stream.CloseSend()<br>   return<br>  }<br><br> }()<br><br> go c.recvUpdates(ctx)<br> return c<br>}<br><br>func (c *client) recvOneUpdate() (string, error) {<br> if c.stream == nil {<br>  return &quot;&quot;, errors.New(&quot;stream not initialized &quot; +<br>   c.cliName + &quot; &quot; + c.grpcAddr)<br> }<br><br> update, err := c.stream.Recv()<br><br> if update != nil {<br>  return update.Info, err<br> }<br><br> return &quot;&quot;, err<br>}<br><br>func (c *client) recvUpdates(ctx context.Context) {<br> for {<br>  select {<br>  case &lt;-ctx.Done():<br>   return<br>  default:<br>   update, err := c.recvOneUpdate()<br>   if err != nil {<br>    c.Errors &lt;- err<br>    c.ensureStream(ctx)<br>    continue<br>   }<br>   c.Updates &lt;- update<br>  }<br> }<br>}<br><br>func (c *client) ensureStream(ctx context.Context) {<br> for {<br>  select {<br>  case &lt;-ctx.Done():<br>   return<br>  default:<br>   if c.grpcConn != nil {<br>    c.grpcConn.Close()<br>   }<br><br>   s, err := c.Connect(ctx)<br>   if err != nil {<br>    c.Errors &lt;- err<br>    fmt.Println(&quot;Sleeping for a bit and trying to connect again&quot;)<br>    // A second of wait time so as to not flood the server.<br>    time.Sleep(time.Second)<br>    continue<br>   }<br>   c.stream = s<br>   fmt.Println(&quot;got the stream now breaking&quot;)<br>   return<br>  }<br> }<br>}<br><br>func (c *client) Connect(ctx context.Context) (learn.Learn_GossipClient, error) {<br> fmt.Println(&quot;Trying to connect to server&quot;)<br> conn, err := grpc.Dial(c.grpcAddr, grpc.WithInsecure())<br> if err != nil {<br>  return nil, errors.New(&quot;Error connecting to grpc server &quot; + err.Error())<br> }<br><br> c.grpcConn = conn<br><br> req := &amp;learn.GossipRequest{<br>  Id: c.cliName,<br> }<br> grpcCli := learn.NewLearnClient(conn)<br><br> stream, err := grpcCli.Gossip(ctx, req)<br> if err != nil {<br>  return nil, errors.New(&quot;Error gossiping &quot; + err.Error())<br> }<br> return stream, nil<br>}<br><br>func main() {<br> grpcAddr := &quot;0.0.0.0:8080&quot;<br> cliName := &quot;cli-abc&quot;<br><br> cli := New(grpcAddr, cliName)<br><br> var wg sync.WaitGroup<br><br> wg.Add(1)<br> go func() {<br>  defer wg.Done()<br>  for {<br>   select {<br>   case update := &lt;-cli.Updates:<br>    fmt.Println(&quot;Update from server: &quot;, update)<br><br>   case err := &lt;-cli.Errors:<br>    fmt.Println(&quot;Errors from server: &quot;, err.Error())<br>   }<br>  }<br> }()<br><br> fmt.Println(&quot;Client started&quot;)<br> wg.Wait()<br>}</pre><h4>Server-Side Code</h4><p>On the server side, multiple clients can connect to a single server. Each connection can be identified by a unique ID, and connections can be stored in a map. This approach is particularly useful for applications like multiplayer games, where clients can interact with each other. The server can push messages to the clients whenever needed.</p><pre>package main<br><br>import (<br> &quot;errors&quot;<br> &quot;fmt&quot;<br> &quot;net&quot;<br> &quot;strconv&quot;<br> &quot;time&quot;<br><br> &quot;github.com/georgethomas111/img-proxy/learn&quot;<br> &quot;google.golang.org/grpc&quot;<br>)<br><br>type StreamingServer struct {<br> learn.UnimplementedLearnServer // Embed the unimplemented methods<br> streams                        map[string]chan string<br>}<br><br>func (s *StreamingServer) Gossip(req *learn.GossipRequest, stream learn.Learn_GossipServer) error {<br> if req == nil {<br>  return errors.New(&quot;Request cannot be nil&quot;)<br> }<br><br> s.streams[req.Id] = make(chan string)<br><br> ctx := stream.Context()<br> for {<br>  select {<br>  case &lt;-ctx.Done():<br>   fmt.Println(&quot;Received done from client, exiting&quot;)<br>   delete(s.streams, req.Id)<br>   return nil<br>  case info := &lt;-s.streams[req.Id]:<br>   msg := &amp;learn.Messages{<br>    Info: info,<br>   }<br>   err := stream.Send(msg)<br>   if err != nil {<br>    fmt.Println(&quot;Error streaming message from &quot;+<br>     &quot;server to client with id &quot;, req.Id, err.Error())<br>   }<br>  }<br> }<br><br> return nil<br>}<br><br>// Update time updates the current time to all the clients.<br>func (s *StreamingServer) UpdateTime() {<br> timeString := strconv.Itoa(int(time.Now().Unix()))<br><br> for id, stream := range s.streams {<br>  fmt.Println(&quot;Trying to write message to stream &quot;, id, timeString)<br>  stream &lt;- timeString<br> }<br>}<br><br>func (s *StreamingServer) Start(grpcAddr string) error {<br> lis, err := net.Listen(&quot;tcp&quot;, grpcAddr)<br> if err != nil {<br>  return err<br> }<br><br> g := grpc.NewServer()<br> learn.RegisterLearnServer(g, s)<br><br> fmt.Println(&quot;Listening for grpc requests on &quot;, grpcAddr)<br> return g.Serve(lis)<br>}<br><br>func New() *StreamingServer {<br> return &amp;StreamingServer{<br>  streams: make(map[string]chan string),<br> }<br>}<br><br>func main() {<br> grpcAddr := &quot;0.0.0.0:8080&quot;<br> s := New()<br> go func() {<br>  for {<br>   select {<br>   case &lt;-time.After(time.Second):<br>    s.UpdateTime()<br>   }<br>  }<br> }()<br> err := s.Start(grpcAddr)<br> if err != nil {<br>  fmt.Println(&quot;Error starting server &quot;, err.Error())<br> }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VtZE1PxyZBF0xvT3nCoG4g.png" /></figure><p>The screen shot shows a sample run of how the client and server will interact. So the client could come up anytime and the server can come up whenever and the messages can be sent between them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cR8Aaemz-U3V4xt44bj9KA.png" /></figure><p>If you take a step further, its possible to have multiple clients connect to a GRPC server. In this case the map only saves the latest connection but that should be easy to fix so that messages get sent to both.</p><p>If you want to check the code and the commit used, it can be found <a href="https://github.com/georgethomas111/img-proxy/tree/ec9209d022825d04c34365d64f007b37c9920a3f">here.</a> Hope you found this interesting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e42b0549301" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Distributed Systems: Let’s talk about Consistency]]></title>
            <link>https://medium.com/@georgeagain/distributed-systems-lets-talk-about-consistency-1230c6a45e06?source=rss-55248a3646fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/1230c6a45e06</guid>
            <category><![CDATA[consensus]]></category>
            <category><![CDATA[scaling]]></category>
            <category><![CDATA[hashing]]></category>
            <category><![CDATA[consistency]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[George Thomas]]></dc:creator>
            <pubDate>Mon, 06 May 2024 03:13:54 GMT</pubDate>
            <atom:updated>2024-05-06T06:04:38.102Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s say you have a social media platform where users can upload and update their profile pictures. Imagine you maintain an image update service with an API to upload images.</p><h3><strong>Strong Consistency</strong></h3><p>If the application has Strong Consistency then it means, if a user updates their profile picture, any subsequent requests to view that profile picture will reflect the latest change immediately. So, there’s no chance of seeing the old picture after it’s been updated. It ensures that the data is always up-to-date and reflects the latest changes made by users.</p><p>The definition of such a consistency could be made as follows:</p><p>“Consistency can be understood as after a successful write, update or delete of a Record, any read request immediately receives the latest value of the Record.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*icDBbsIThJTMswJP8-uVxQ.png" /><figcaption>A strongly consistent system with a replica</figcaption></figure><p>The diagram above could represent the picture of a system which has strong consistency where there is a primary server to receive the read and write requests. The replica gets synchronized periodically so that if an outage happens the backup replica will have data.</p><p>The reads and writes are handled by similar nodes(machines) in this case. The writes followed by a read will always get you the last updated image.</p><p>The single node is also a bottle neck as the maximum number of image updates that you can serve is equal to the ability of the node. Different customers will have to wait for the DB writes and reads of others to complete.</p><h3>Improve throughput by hashing</h3><p>The current bottle-neck is the single node. It’s possible to increase the number of nodes so that each customer potentially talks to different nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*efRq5XBPGd3fMMuW9qlNXg.png" /><figcaption>Hashing helps improve throughput</figcaption></figure><p>Hashing can help to improve the throughput for the customers. So if two customers are uploading or reading images, they could go to two systems which helps to ensure that both these requests can move forward without having to wait for the other.</p><p>For a general application there is usually more reads than writes. So for the image API in question, the image gets changed not too frequently. So the traffic to read the image is much more than the traffic to write images. With the design of a system like the one described above with hashing, we still over allocate instances for the writes. The replica also needs to exist for each of the primary DB instances to prevent loss of data if one instance goes down.</p><p>Changing the expectations of consistency can help us reduce the number of instances needed.</p><h3>Eventual Consistency</h3><p>If the application has Eventual Consistency then it means, if a user updates their profile picture, any subsequent requests to view that profile picture may not reflect the latest change immediately but will eventually see the latest update. So, there’s some chance for them to see the old picture after it’s been updated.</p><p>Let’s look at the definition of eventual consistency.</p><p>“After a successful write, update, or delete of a Record, eventual consistency allows for the possibility that not all read requests immediately receive the latest value of the Record. Instead, the system will eventually converge to a consistent state, ensuring that all read requests will eventually reflect the most recent changes made to the Record.&quot;</p><p>On the surface this sounds really bad compared to the case with strong consistency. If the eventual consistency happens within a few seconds it may not even be noticeable for customers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vs4GjVyWsCtgkyRv8YlATw.png" /><figcaption>Eventually consistent database with separate Read and Write data nodes</figcaption></figure><p>Eventual consistency does come with a lot of advantages with how the systems can be designed and scaled. It’s possible to have low latencies as the DB writes and Reads can happen at different locations without having to wait for each other to complete. Overall it’s possible to have less data stored at one location or all the data can be stored at all locations if you are sensitive to latency.</p><p>This blog is a quick overview of the concepts and in future I will try to talk about some practical databases like Cassandra, etcd and cockroach and see how they handle the communication between the nodes. We can also try to see if these are strongly consistent or eventually consistent databases.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1230c6a45e06" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generating simple charts from a go program]]></title>
            <link>https://medium.com/@georgeagain/generating-simple-charts-from-a-go-program-d1c24f3962e9?source=rss-55248a3646fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1c24f3962e9</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[charts]]></category>
            <category><![CDATA[autoregression]]></category>
            <dc:creator><![CDATA[George Thomas]]></dc:creator>
            <pubDate>Fri, 12 Apr 2024 05:53:45 GMT</pubDate>
            <atom:updated>2024-04-12T05:58:55.740Z</atom:updated>
            <content:encoded><![CDATA[<p>When I started this project, my goal was not about drawing graphs but here we are writing about the charts I drew. It was primarily to study some statistics. While trying to do that I realized something as simple as drawing graphs is hard if you don’t use R or python.</p><p>I like the simplicity of charts that can be drawn and produced as static HTML. While writing Go, its hard to think about HTML and vice-versa. So here the HTML code generation is abstracted and in Go, graphs and time-series can be created by using something simple as the code that follows.</p><pre> t, err := timeseries.ReadCSV(d)<br> ...<br> chartIndex := 0<br> c0 := timeseries.Chart(&quot;first chart&quot;, t, chartIndex)<br> chartIndex = 1<br> c1 := timeseries.Chart(&quot;second chart&quot;, t, chartIndex)<br> html, _ := timeseries.NewHTML(&quot;Creating charts&quot;, story)<br> html.Charts = append(html.Charts, c0)<br> html.Charts = append(html.Charts, c1)<br> htmlFileName := &quot;latest.html&quot;<br> html.Render(&quot;./&quot; + htmlFileName)<br> timeseries.StartServer(htmlFileName)</pre><p>The input is a simple CSV file which contains a date and a value corresponding to that date with a simple format.</p><pre>cat inputs/unique_visitors.csv <br>timestamp,value<br>2023-Aug-27,2<br>2023-Aug-28,6<br>....</pre><p>The code for this really simple project can be found here. My idea was to use this time-series chart to play with the input data and infer more about what is in the data. To do this in Go, I just had to start from scratch.</p><p><a href="https://github.com/georgethomas111/auto-regression">GitHub - georgethomas111/auto-regression</a></p><pre>$ go run cmd/auto/auto.go inputs/unique_visitors.csv <br>Serving files in this director over port. Press Cntrl+C to exit. 8080<br>View the generated charts at http://localhost:8080/latest.html</pre><p>This should start the server which listens on port 8080 and you should see a page that looks like the one below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cc6J1IumWmuP5cfHSmDgKQ.png" /></figure><p>The story section is to force the person creating the graph to describe what it is as its a good practice to do so.</p><p>Sorry that dark mode does not exist. I haven’t figured enough HTML to figure that part out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1c24f3962e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Can I run Standalone Javascript using Mozilla Spidermonkey like how NodeJS uses v8?]]></title>
            <link>https://medium.com/@georgeagain/can-i-run-standalone-javascript-using-mozilla-spidermonkey-like-how-nodejs-uses-v8-5f62ad0b3917?source=rss-55248a3646fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f62ad0b3917</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[v8-engine]]></category>
            <category><![CDATA[wasm]]></category>
            <category><![CDATA[firefox]]></category>
            <category><![CDATA[spidermonkey]]></category>
            <dc:creator><![CDATA[George Thomas]]></dc:creator>
            <pubDate>Thu, 28 Dec 2023 08:39:33 GMT</pubDate>
            <atom:updated>2023-12-28T08:39:33.443Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>What is SpiderMonkey?</strong></h3><p><a href="https://spidermonkey.dev/">Spidermonkey</a> is a project which is still used by the firefox web browser. Its like the <a href="https://v8.dev/">v8</a> engine that people might have heard about from the chrome team. Node JS runs on the v8 engine and even <a href="https://developers.cloudflare.com/workers/">Cloudflare Workers</a> which runs really well on the server side.</p><p>Using browser engines to run server side code is not a new concept and v8 has been used for it for a while. I wanted to see if its possible to use Spidermonkey to run some javascript. Spidermonkey is different from v8 in a way that the javascript is not compiled to bytecode all the time in Spidermonkey. They do lazy compilation of only the parts that matter and is used frequently. There are multiple compilers which exist <a href="https://firefox-source-docs.mozilla.org/js/index.html">within spidermonkey</a> that accomplishes this. If you want to try Spidermonkey live try the <a href="https://wasi.dev/">WASI</a> implementation of it <a href="https://mozilla-spidermonkey.github.io/sm-wasi-demo/">here.</a></p><p>There was a time when there was an effort to rewrite parts of Firefox in Rust.<a href="https://servo.org/"> Servo</a> is a project that handled this. The renderer is written primarily in Rust but the javascript engine continued to be written in C++. So an <a href="https://github.com/servo/mozjs">API</a> called mozjs was exposed for Servo to talk to js engine in spidermonkey.</p><p>This API can be the base for creating something which runs javascript on spidermonkey without the browser.</p><p>The code that accomplishes this can be seen here. So its basically a standalone form for the tests they have in spider monkey rewritten using the Rust API that allows talking to spider monkey. You can check the code there.</p><p><a href="https://github.com/georgethomas111/wasm-runner/tree/master/mozjs-runner">wasm-runner/mozjs-runner at master · georgethomas111/wasm-runner</a></p><pre>$ cargo build</pre><p>You will find a lot of warnings as I use unsafe but it builds eventually.</p><pre>$ ./target/debug/mozjs-runner `cat jsExp/utcDate.js`<br>Input script -&gt; &quot;let d = new Date()\nd.toUTCString()&quot;<br>Sun, 03 Dec 2023 23:11:06 GMT</pre><p>So it does work!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7sfrIZIMD-SlaC3yA3860A.png" /><figcaption>Screenshot of how it runs on my terminal</figcaption></figure><p><strong>What is the size of the executable?</strong></p><p>The skeptic inside me wanted to see how big the size of the executable is.</p><pre>$ du -sh target/release/mozjs-runner<br>478M target/release/mozjs-runner</pre><p>This is not a small binary. Will this work as a way to run javascripts in Production. I am actually not sure. It may work but will it be better than node js, probably not. Also none of the scripts that I have tried are long running. So if anyone is interested in playing with it more, please do check it out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f62ad0b3917" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>