In this blog post, we introduce the Swift-Enterprise-Demo application, one of the most recent demo apps that our team (Swift@IBM) has developed. This application highlights some of the new enterprise capabilities you can leverage when you deploy your Swift and Kitura-based applications to the Bluemix cloud. Using a cloud offering, such as Bluemix, for provisioning and running your applications allows you to focus on implementing business logic and features and not worry about server and hardware maintenance. However, there are more advantages for hosting your Kitura-based applications on the cloud as we will see next.
Reacting appropriately to spikes in application usage is critical to ensure your application remains responsive under heavy loads. Though you can scale your application manually using the Cloud Foundry command line or your application’s dashboard on Bluemix, wouldn’t it be better if you could scale your application automatically? The latest version of the Auto-Scaling service in Bluemix allows users to create custom policies for dynamically scaling their Swift applications horizontally. Using this service, developers can define rules that use memory usage, http response time, and http throughput metrics for creating additional instances of the application (i.e. scaling out). In these rules, you can also define the conditions for removing instances of your application (i.e. scaling in) when the spike has gone down.
The Auto-Scaling service also gives you the ability to have more fine-grained control over the rules you define. For instance, you scan specify the amount of time the application must “cooldown” before it can scale in our out again. You can also specify the amount of time the application must remain “out of bounds” (i.e. breach time) before a scaling action could be triggered (by “out of bounds” we mean that the collected metrics are either above the upper threshold or below the lower threshold). Binding your Kitura-based application to the Auto-Scaling service will give you the keys to fine-tune and control how your application should scale based on usage spikes without requiring manual intervention from you.
The Swift-Enterprise-Demo application showcases the Auto-Scaling service by providing a user interface that allows you to increase and decrease the memory usage of the application; add a delay to HTTP responses; and increase or decrease the number of HTTP requests per second against the application. By changing the values of these parameters, you can then see how the application scales in and out based on the rules defined in the Auto-Scaling service instance.
For further details on the Auto-Scaling service, see the Bluemix documentation.
The Alert Notification service on Bluemix can be used to receive early notifications about issues affecting your applications and services before they can impact your users. The Alert Notification service allows users to create rules for filtering and processing alerts sent out from applications and services. These rules can determine whether or not a notification should be sent to a member(s) of your IT support staff. For example, you could define a rule that states that a notification should be sent to the admin group whenever an alert of critical severity has arrived. The Alert Notification service supports notifying a person or groups via different channels such as email, text messaging, voice, Slack, and push notifications.
To instrument your Swift code to send alerts when important events occur, you can use the new Alert Notification SDK for Swift. The Swift-Enterprise-Demo application leverages this new SDK to send alerts when important events occur in the application. For example, the application sends out an alert when memory usage is high or when it is taking a long time to send out an HTTP response.
For more details on the Alert Notification Service, see the Bluemix documentation.
The Circuit Breaker design pattern is used to prevent a failure from reoccurring in a system. Using this design pattern prevents an application from executing an action that will fail; re-executing that same action will be allowed once it is safe. For example, say that an application relies heavily on a database and this database becomes unresponsive. Instead of letting all database requests from the application go through and fail because of TCP connection timeout errors, the application can instead handle the error quickly until the database is back up again.
Our team recently released the first version of our Circuit Breaker (https://github.com/IBM-Swift/CircuitBreaker) library for Swift applications. The Swift-Enterprise-Demo application showcases this library by providing widgets to control the availability of an external endpoint and its response time. By changing the status of the external endpoint with these controls, you can see how the CircuitBreaker library reacts and allows or prevents the application from making network calls to this remote endpoint. For example, after disabling the endpoint and invoking it three times, the Circuit Breaker library “opens the circuit” and does not allow any more invocations of that endpoint for one minute. After that minute has elapsed, the library will allow an invocation to the endpoint go through and, if it fails, it will not allow any other invocations for another minute.
Using the UI of the browser component, you can also increase the response time of the remote endpoint to explore the functionality around timeouts that our Circuit Breaker library provides. If the response from invocation of the endpoint takes longer than ten seconds, then that invocation is considered a failure.
Please note that all the threshold values (e.g. number of failures before opening the circuit; the amount of time before allowing a call to go through after a failure; timeout window, etc.) used by the Circuit Breaker library are configurable (i.e. when you create an intense of the Circuit Breaker, you can specify these values).
For more details on the capabilities and functionality on the new Circuit Breaker library for Swift, we invite you to check out its README file on GitHub. Also, feel free to check out the Stabilize your Swift applications with CircuitBreaker blog post.
Our team put together three videos that demonstrate how to use the Swift-Enterprise-Demo app for showcasing the enterprise capabilities described above:
We are excited to have now these new enterprise capabilities available for Swift applications. Using such capabilities in your applications will help you build robust, scalable, and maintainable solutions for your customers. Let us know what you think of these new features and of any other capabilities you will like to see!
For more information on server-side Swift, visit the Swift@IBM Developer Center.