1. Home
  2. Docs
  3. Finance
  4. Lovia Billing Service

Lovia Billing Service

Lovia Billing Service is a web service and worker that handles integration with financial services (Xendit, ERPNext, and ChartMogul) and marketing service (Mautic). It is operated by Finance Tech team. It is a critical business component and must be running with high availability.

Lovia Billing version 5.0 version is developed using NestJS. Heartenly Billing version 4.0 was using Express and TypeScript. OpenAPI for Heartenly Billing 4.0 (deprecated) was in https://app.swaggerhub.com/apis/lovia/heartenly-billing/4.0.0, next version auto-generates OpenAPI spec and prefers GraphQL if possible.

Repository: https://gitlab.com/lovia/lovia-billing branch master (Lovia Billing 5.0) and v4.x (Heartenly Billing 4.0).

Docker Build & Deployment

Heartenly Billing 4.0 was deployed on Amazon Lambda. Due to duplicate-request problems, resulting in duplicate invoices & payments, we now deploy as Docker container to AWS Fargate as a workaround.

Build & Push Container to GitLab Container Registry

To trigger GitLab CI build, push master to branch staging or production:

# Build staging
git push origin master:staging
# Build production
git push origin master:production

In AWS Fargate Singapore, there are two task definitions for staging and production, with GitLab Deploy Token so private containers are accessible. We need to use AWS Secrets Manager to access the private GitLab containers ($0.40/secret/month):

  1. Create the secret in AWS Secrets Manager
  2. Create a task execution role to include policy to access the secret
  3. Reference the secret’s ARN in task definition, and use the privileged task execution role

Build Locally & Push Container to AWS Elastic Container Registry

Alternatively, we can push the Docker image directly to AWS Elastic Container Registry and pay $0.10/GB/month instead. To use AWS ECR, create ECR repository and enable “Scan on push”:

On your local computer, authenticate Docker client to AWS ECR:

aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin 703881650703.dkr.ecr.ap-southeast-1.amazonaws.com

Build:

docker build --tag lovia/lovia-billing .

Push:

docker tag lovia/lovia-billing 703881650703.dkr.ecr.ap-southeast-1.amazonaws.com/lovia/lovia-billing
docker push 703881650703.dkr.ecr.ap-southeast-1.amazonaws.com/lovia/lovia-billing

AWS Fargate Services

Two AWS Fargate services run these task definitions with default security group. The images bundle curl, so you can have Fargate healthcheck using:

CMD-SHELL, curl -f http://localhost:3005/ || exit 1

The AWS Fargate services are then accessible using alb-lovia-sg2 application load balancer.

To make it easier to route URLs, each service, version, and environment has its own URL.

VersionStagingProduction
Lovia Billing 5.0https://billing-v5-staging.lovia.lifeTask definition: lovia-billing-v5-production
https://billing-v5.lovia.life
Lovia Billing URLs

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *