A Company’s Story Crystallized: Duo Design

Cris Ward is Company Director at Duo Web Design,[33] which is a web design agency focusing on delivering dynamic web and digital solutions. It is based in Manchester, U.K.

Ivo:

What production projects do you use Crystal for?

Cris Ward:

Our main project is Duo CMS (Content Management System); it is in it’s fifth incarnation as Duo CMS 5. In active development since 2004, the server part of the system has undergone a recent rewrite in Crystal to make it more flexible and performant for the modern web. We utilise our CMS system for most of our customer websites and web applications as it provides us a high level of customization to achieve the best balance between performance and ease of use for our clients.

Ivo:

Why did you decide to use Crystal for these applications? 

Cris Ward:

At Duo, we’ve been using Node.js as our server platform of choice for a number of years. Node is designed to do every task asynchronously. This means that, by default, if you ask it to do five tasks, it will try and do all of them at the same time. Node solves this with promises, allowing the programmer to chain together a series of asynchronous tasks into a series of individual steps performed one after another.

On the server, having parallel tasks as the default seems like a very efficient idea. In reality, most of the tasks we perform as developers require data from the previous task. Even when we can perform the tasks in parallel, the resources of the system can get quickly exhausted—i.e., making lots of parallel requests to the database can exhaust your pool of connections and lower the number of concurrent users you can serve.

During our years using node, creating promise chains became normal. Half the code written was about turning async tasks into sequential tasks. These chains became difficult to test, debug, and understand. It can be very difficult, just by looking at the code, to see in which order the tasks, and various sub-tasks, are executed.

Ivo:

What kinds of problems does Crystal solve best?

Cris Ward:

We use it with great success as a server-side processing language, running SQL queries against a database, utilizing ORMs, reading and writing files, and linking with third-party APIs.

Ivo:

What was it like to develop with Crystal?

Cris Ward:

This is what I found when rewriting our server-side CMS:

• Crystal is quick, in my tests often x2 as quick as Node for my use case.

• It uses very little memory—typically greater than 5MB versus less than 200MB per process for Node.

• It has an excellent standard library, so we have only 12 dependencies in total, compared to Node’s 100s.

• Code looks synchronous by default. It uses an event loop like node, but Fibers, which communicate through channels like Go, are used for concurrency. This makes code much easier to follow.

• Crystal is statically typed so it tells you at compile time if you’ve made any errors.

• Crystal’s type system infers types so it’s very easy to use as you don’t need to use type annotations very often.

Ivo:

Are there any aspects of Crystal that specifically benefit customer satisfaction?

Cris Ward:

Its execution speed, and the early detection of possible errors during development, saving us and our customers some headaches.

Ivo:

What advantages or disadvantages have you experienced from deploying a Crystal application in production? 

Cris Ward:

The DuoCMS 5 server code written in Node.js is around 15,609 lines of JavaScript; DuoCMS 6, rewritten in Crystal, is about 10,186 lines. At this point in time, DuoCMS 6 actually has more features with 30 percent fewer lines of code and no confusing control flow! Compare some of the Node and Crystal code here: https://www.duodesign.co.uk/blog/from-node-to-crystal/.

Ivo:

What do you like the most about Crystal, compared to other languages?

Cris Ward:

While using Node, I evaluated lots of other languages and platforms, including Python, PHP, Ruby, and Go. They tended to be either slower than node or not as nice to write. Speed and syntax are both things within a language that you can optimise but never really improve beyond a certain point. When I read about Crystal, I decided to emulate some of the server-side portions of our content management system. This turned out to be pretty awesome. I enjoyed writing Crystal so much that we’ve recreated our whole CMS backend in Crystal. Also, our website is rewritten in Crystal.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.101.81