Crystal for new projects

I started a new position knowing there were some problems with the codebase. After a month the owner of the company and I have both come to the conclusion we need to rewrite the project. My first choice would be Crystal.

There are some libraries we need immediately that too be honest are just not well supported or do not exist in crystal. But I can get around the near term problems.

I wanted to hear from the community. What is the current state on production support and operations?

I need a suite of operations tools that integrate into a web framework. Mostly:
Metrics
APM
Logging
Incident response

Also it would be nice to know if there are any glaring holes in the ecosystem. It seems like AWS support is still lacking.

Anyways let me know your thoughts on the current state of Crystal in a production environment.

8 Likes

Just curious: what AWS services specifically do you need to access from Crystal?

AWS, it’s been a long time since I worked with it,

I was maintaning AWS shard GitHub - sdogruyol/aws: Unofficial AWS SDK for Crystal (S3, SQS support) but nowadays I don’t use AWS or have time for it. Maybe someone can fork or revive it back?

1 Like

Based on the size of the program you want to deploy, openfass is also a option. there are a Crystal binding live maintain.

OpenTelemetry could be a good tool for most (all?) the monitoring features you’re looking for:

2 Likes

Are you fixed/prefer a certain web framework and incident response services?

congrats on the new position!

1 Like

There is a great work to use Opentelemtry with Crystal: GitHub - wyhaines/opentelemetry-instrumentation.cr: Bundled integrations for opentelemetry-api.cr (https://github.com/wyhaines/opentelemetry-api.cr).

The first doc how to use it in https://newrelic.com/blog/how-to-relic/otel-crystal
but the library changed from time of written and presented in that article, so read the code.

Getting started from me on earliest version: How to begin with Traces in Crystal | by Michael Nikitochkin | JTWay

3 Likes

right now dynamodb. There is a shard for it but it is lacking features.

Thanks!!! It has been a real journey.

I prefer Lucky Framework because I feel it leans into Crystals strengths but I am open to options.

I don’t have a preference for incident response services but I have used a few and there seems to be some that are better then others.

Thanks!

I tried the repo a while ago I should give it another shot.

Depending on what kind of application you’re making is, Athena could also be a good choice :slight_smile:. I’d be happy to answer any questions etc if needed as well.

Does Athena have an ORM?

Not directly within its ecosystem. But would be able to use whichever (if any) you wanted. E.g. Jennifer, Granite, Clear, etc.

Alternatively, I found just using DB::Serializable - db 0.11.0 works quite well. Is easy enough to add some helper methods to leverage more of the repository pattern so you only have to really write the SQL once when/if you need a new repo method. You also have to handle inserts yourself, but similarly can exact that to some helper type(s).

I’m still planning on getting an updated version of a example demo application available to serve as reference, based on the blog application from the book. It’s a somewhat naive implementation to keep the book length down, but can serve as a good starting point. Tl;dr being:

  • Article - The primary entity (model) of the application. Includes some modules to make it be JSON (de)serializable, serializable from the DB, and validatable. Depending on the complexity of your application it may serve better to have a dedicated object to represent the request/response bodies versus coupling that with your DB entity. The entity also has some protected methods that act as simple DB hooks, these could be extracted into a base type/module for better reusability.
  • Article::Repository - Contains all methods used to query for articles. Similar to the entity itself, common query methods like #find, #find?,#find_all, and #find_by could be implemented in an abstract repo type with generic as the as argument.
  • EntityManager - Primary type used to interact with the DB from your business logic. Contains public methods to create/update a record, as well as to delete them. Also contains a method to get an Article::Repository instance cached in a class var. Could use a macro to auto-generate these for all entity types. Lastly this type contains the raw SQL used as part of the creation/updating process, which should return the PK of that entity to properly set its #id value. Could maybe do something again with macros to auto generate two methods, one for the column names, and another for column values (all based on ivar names or something).
  • ArticleController - Example of how the entity manager can be used along with the EntityManager. This is for an older version of Athena, the ParamConverter concept changed, so syntax is not 100% what it would be in the latest version. This controller also makes use of a custom converter that provides the record from the DB in addition to the one deserialized from the request payload. Mainly useful for PUT requests, (and maybe PATCH?).
3 Likes

I had not considered using DB::Serializable but that is a great idea. I think this is actually a really good idea. The hard part is getting from 0 to 1. Getting a fast initial iteration for CRUD and everything is hard. It would be an interesting project to have something scaffold up an initial web application.

It’s still a WIP, but can checkout GitHub - athena-framework/demo at develop. Still need to add an example of auth, update the README.md files, and add some more tests but it should give you the gist of my previous reply and/or serve as an alternate starting point versus the skeleton repository.